-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchArray.java
More file actions
41 lines (32 loc) · 937 Bytes
/
SearchArray.java
File metadata and controls
41 lines (32 loc) · 937 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
32
33
34
35
36
37
38
39
40
41
//7:Write a Java program , accept array ,accept number from user and
//find the index of number in array if present else show message not exist.
import java.util.Scanner;
public class SearchArray {
public static void main(String[] args) {
int size=1,num;
boolean flag=true;
Scanner input=new Scanner(System.in);
System.out.print("Enter Array size :");
size=input.nextInt();
int arr[ ] = new int[ size ];
for(int index = 0; index<arr.length ; index++ ) {
System.out.print("Enter Array elements :");
arr [index ] = input.nextInt();
}
System.out.print("Enter number to Search :");
num=input.nextInt();
for(int index = 0; index<arr.length ; ++index ) {
if(num==arr[ index ]) {
flag = true;
break;
}
else
flag = false;
}
if(flag==true)
System.out.println("Number is exist");
else
System.out.println("Number is not exist");
input.close();
}
}