Skip to content

Commit fb1f417

Browse files
committed
Solutions to Search An Element
1 parent 2737a9f commit fb1f417

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/Scaler/Assignments/SearchElement.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public static void main(String[] args) {
88
Scanner scanner = new Scanner(System.in);
99
int testCases = scanner.nextInt();
1010

11+
boolean isNumberFound = false;
12+
1113
for(int i = 1; i <= testCases;i++){
1214

1315
int length = scanner.nextInt();
@@ -16,27 +18,25 @@ public static void main(String[] args) {
1618

1719
for (int k = 0; k < array.length; k++)
1820
{
19-
array[i] = scanner.nextInt();
21+
array[k] = scanner.nextInt();
2022
}
2123

2224
System.out.println(array);
2325

2426
int searchNumber = scanner.nextInt();
2527

26-
boolean isNumberFound = false;
27-
2828
for (int j = 0; j < array.length; j++){
2929
if (array[j] == searchNumber){
3030
isNumberFound = true;
3131
break;
3232
}
3333
}
34+
}
3435

35-
if (isNumberFound){
36-
System.out.println(1);
37-
}else {
38-
System.out.println(0);
39-
}
36+
if (isNumberFound){
37+
System.out.println(1);
38+
}else {
39+
System.out.println(0);
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)