-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.java
More file actions
31 lines (28 loc) · 999 Bytes
/
Copy pathSearch.java
File metadata and controls
31 lines (28 loc) · 999 Bytes
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
/**Author: Anand A Jain
* Date:30-07-2025
* Search for a number in the array and print its position if found, or a message if not found.
*/
import java.util.*;
public class Search {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of terms");
int n = in.nextInt();
int[] num = new int[n];
System.out.println("Enter The numbers");
for (int i = 0; i < n; i++)
num[i] = in.nextInt();
System.out.println("Enter the number to be searched");
int number = in.nextInt();
int flag = 0;
for (int i = 0; i < n; i++) {
if (num[i] == number) {
flag = 1;
System.out.println("The number is found in the position " + (i + 1));
break;
}
}
if (flag == 0)
System.out.println("The number is not found");
}
}