add increments to each elements of the array

This commit is contained in:
Siwat Sirichai 2020-10-21 00:05:23 +07:00
parent 4b16ccf00e
commit d4cdc278dd
2 changed files with 2 additions and 1 deletions

View File

@ -13,11 +13,12 @@ public class CountNumbers {
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;i<int_array.length;i++)int_array[i]=sc.nextInt(); //populate the array with the file's value
for(int i = 0;i<int_array.length;i++)int_array[i]++; //Increase each elements of the array by 1
System.out.println("The number of integers greater than 25: "+greater(int_array,25));
System.out.println("The number of integers greater than 25: "+greater(int_array,50));
System.out.println("The number of integers greater than 25: "+greater(int_array,75));
} catch(FileNotFoundException e) {
System.out.println("File \"numbers.txt\" is not found in the current directory!"); //If no fie named numbers.txt is found, show "File "numbers.txt" is not found in the current directory!" and exit the program with exit code 0
System.out.println("File \"numbers.txt\" is not found in the current directory!"); //If no file named numbers.txt is found, show "File "numbers.txt" is not found in the current directory!" and exit the program with exit code 0
System.exit(0);
}