We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents e40589c + 56aa950 commit a0a0d34Copy full SHA for a0a0d34
Searching.java
@@ -0,0 +1,37 @@
1
+import java.util.Scanner;
2
+public class Searching {
3
+ public static int search(int arr[], int x) {
4
+ for (int i = 0; i < arr.length; i++) {
5
+ if (arr[i] == x) {
6
+ return i;
7
+ }
8
9
+ return -1;
10
11
+ public static void main(String[] args) {
12
+ Scanner input = new Scanner(System.in);
13
+ int arr[] = {
14
+ 10,
15
+ 20,
16
+ 30,
17
+ 40,
18
+ 50,
19
+ 60,
20
+ 70,
21
+ 80,
22
+ 90,
23
+ 100
24
+ };
25
+ System.out.print("Enter the number: ");
26
+ int x = input.nextInt();
27
+ System.out.println();
28
+
29
+ int result = search(arr, x);
30
+ if (result == -1) {
31
+ System.out.println("Sorry, data not found");
32
+ } else {
33
+ System.out.println("Number " + x + " in index " + search(arr, x) + "");
34
35
36
37
+}
0 commit comments