-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProblem1.java
More file actions
49 lines (35 loc) · 1.35 KB
/
Problem1.java
File metadata and controls
49 lines (35 loc) · 1.35 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
package Lab_Task_1;
import java.util.Scanner;
public class Problem1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String search_mobile;
boolean flag = false;
System.out.println("Number of Mobile: ");
int n = scanner.nextInt();
String[] mobile_name_akash = new String[n];
int [] mobile_price_akash = new int[n];
for (int i=0; i<n; i++){
System.out.print("Mobile Name: ");
mobile_name_akash[i] = scanner.next();
System.out.print("Mobile price: ");
mobile_price_akash[i] = scanner.nextInt();
}
System.out.println("\n------Mobile List: ------");
for (int i=0; i<n; i++){
System.out.println("Name: " + mobile_name_akash[i] + "\t Price: " + mobile_price_akash[i]);
}
System.out.println("\nSearch Mobile: ");
search_mobile = scanner.next();
// Search
for (int i=0; i<n; i++){
if (mobile_name_akash[i].equals(search_mobile)){
System.out.println("\n-----Search Result:-----\nName: " + mobile_name_akash[i] + "\nPrice: " + mobile_price_akash[i]);
flag = true;
}
}
if (!flag){
System.out.println("\n-----Search Result:-----\nCan't find it");
}
}
}