-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayData.java
More file actions
55 lines (45 loc) · 1.39 KB
/
arrayData.java
File metadata and controls
55 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ApexDay1;
import java.util.Scanner;
import java.util.Random;
public class arrayData {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// String[] fruits;
// System.out.print("Enter number of fruits: ");
// int size = scanner.nextInt();
// scanner.nextLine();
// fruits = new String[size];
//
//
// for (int i = 0; i <fruits.length; i++) {
// System.out.print("Enter fruits:");
// fruits[i] = scanner.nextLine();
// }
//
// for (int i=0;i<fruits.length;i++) {
// System.out.println(fruits[i]);
// }
//
//scanner.close()
String[] fruits = {"apple", "Banana", "chilli", "tomato" };
Boolean isFound=false;
System.out.print("fruits are :");
for (String fruit:fruits
) {
System.out.print(" "+fruit);
}
System.out.println();
System.out.print("Enter fruit to check : ");
String target = scanner.nextLine();
for (int i = 0; i < fruits.length ; i++) {
if (fruits[i].equals(target)) {
System.out.print("Element found at index " + i);
isFound = true;
break;
}
}
if(!isFound){
System.out.println("Not found");
}
}
}