//This code is written by Siwat Sirichai import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class CountNumbers { public static void main(String[] args) { try { //Since java.io.File throws FileNotFoundException, a try-catch block is neccessary. Scanner sc = new Scanner(new File("numbers.txt")); //This create a scanner with file "number.txt" as an input int length = 0; //define array length initialy at zero for(length = 0;sc.hasNextInt();length++)sc.nextInt(); //Use File Scanner to find the number of elements in the file int[] int_array = new int[length]; //Create an array with length number of elements sc = new Scanner(new File("numbers.txt")); //Send the Scanner's cursor to the top of the file for(int i = 0;iv)count++;//This is called a for-each loop, it will loop for a.length iteration, return count; } }