-2

This is the code which I've tried so far:

int num;
       int[] a={2, 3, 4,7, 9};
       System.out.println("enter a no");
       for(int i=0; i<a.length; i++){
           num= in.nextInt();
           if(num==a[i])
  • See this question. http://stackoverflow.com/a/1128728/1150683 Also, assign the input to the variable before the loop. – Bram Vanroy May 29 '16 at 13:48

1 Answers1

0

It is easy:

int num;
boolean find = false;
   int[] a={2, 3, 4,7, 9};
   System.out.println("enter a no");
   num= in.nextInt();
   for(int i=0; i<a.length; i++){

       if(num==a[i]){
          find = true; 
          break;
       }
   }
System.out.println("Find = " + find);
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140