import java.util.ArrayList; import java.util.Random; import java.util.Scanner; import javax.swing.JOptionPane; /** * * @author Bill Kraynek * * COP3337 Example */ public class ArrayMaxExample { /** * @param args the command line arguments */ public static void main(String[] args) { int[] numbers = new int[10]; Random random = new Random(); for( int i = 0; i < 10; i++ ) { numbers[i] = random.nextInt(20); } //end for while ( true ) { String input = JOptionPane.showInputDialog("Enter a number. Click cancel to quit"); if ( input == null ) return; int number = new Scanner(input).nextInt(); int numberIndex = indexOf(number,numbers); if( numberIndex != -1 ) { JOptionPane.showMessageDialog(null,number + " found in array"); } else { JOptionPane.showMessageDialog(null,number + " not found in array"); } // end if } } static int indexOf(int number, int[] array) { for( int i = 0; i < array.length; i++ ) { if( number == array[i] ) return i; } // end for return -1; } }