// Read numbers from a text file and store them into an array; then // find the largest number, and display it. import java.io.*; import java.util.Scanner; class ArrayEx1 { static public void main(String[] args) throws IOException { Scanner scan = new Scanner (System.in); String inputpath; System.out.print ("Enter the pathname of the input file: "); System.out.flush (); inputpath = scan.nextLine(); Scanner inputFile; inputFile = new Scanner(new File(inputpath)); /* Declare the array */ int[] numbers = new int[50]; int index = 0; /* Read the first number and initialize largest */ numbers[index] = inputFile.nextInt(); int largest = numbers[index]; while (numbers[index] != 0) { index++; numbers[index] = inputFile.nextInt(); } /* Search for the largest element */ for (int count = 1; count < index; count++) if (numbers[count] > largest) largest = numbers[count]; System.out.println("The largest number is " + largest); inputFile.close(); } }