Write a program in java to search a number from a list.
import java.util.Scanner;
class searchNumber{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A[]={1,2,6,4,8,7,9};
System.out.println("Enter the number to search : ");
int n=sc.nextInt();
searchItem(A, n);
sc.close();
}
public static void searchItem(int A[],int n){
for(int i=0;i<A.length;i++){
if(A[i]==n){
System.out.println(n+" is present at index "+i);
break;
}
}
}
}
OUTPUT:
Enter the number to search :
4
4 is present at index 3
Comments
Post a Comment
Please do not enter any spam link in the comment box.