File tree 1 file changed +0
-61
lines changed
1 file changed +0
-61
lines changed Original file line number Diff line number Diff line change 1
- package Techsparx .Arrays ;
2
-
3
1
import java .util .Scanner ;
4
- /**
5
- * Write a description of class linearSearch here.
6
- *
7
- * @author (your name)
8
- * @version (a version number or a date)
9
- */
10
2
public class linearSearch
11
3
{
12
4
public static void main (String args [])
@@ -58,56 +50,3 @@ else if ( flag == false)
58
50
}
59
51
}
60
52
}
61
-
62
- /*
63
- public class linearSearch
64
- {
65
- public static void main(String args[])
66
- {
67
- //declaration
68
- Scanner sc = new Scanner(System.in);
69
- int n, position, key, a[];
70
- boolean flag;
71
-
72
- //reading the number of array elements
73
- System.out.println("Enter the number of array elements: ");
74
- n = sc.nextInt();
75
-
76
- //creating an array of size n
77
- a = new int[n];
78
-
79
- //reading the array elements
80
- System.out.println("Enter " + n + " array elements");
81
- for(int i = 0 ; i < n ; i++)
82
- {
83
- a[i] = sc.nextInt();
84
- }
85
-
86
- //reading the array element to be found/searched
87
- System.out.println("Enter th number to be found: ");
88
- key = sc.nextInt();
89
-
90
- //Linear search
91
- flag = false ; position = 0 ;
92
- for(int i = 0 ; i < n ; i++)
93
- {
94
- if(key == a[i])
95
- {
96
- flag = true;
97
- position = i+1;
98
- break;
99
- }
100
- }
101
-
102
- //chccking flag
103
- if(flag == true)
104
- {
105
- System.out.println(key + " is found at position: " + position);
106
- }
107
- else
108
- {
109
- System.out.println(key + " is NOT found ");
110
- }
111
- }
112
- }
113
- */
You can’t perform that action at this time.
0 commit comments