My code below (passes the server test), model code in image. Some questions that come to mind would be, "Is my code a better way to store information as the program executes for various applications?"; "If this was iterated in, say, doubles, and an extremely high number of times, would the model code be optimal for managing computer resources?". Just a newbie trying to grasp a deeper concept of the "ambiguities" of coding 😄
import java.util.Scanner;
import java.util.ArrayList;
public class NumbersFromAFile {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("File? ");
String file = scanner.nextLine();
System.out.print("Lower bound? ");
int lowerBound = Integer.valueOf(scanner.nextLine());
System.out.print("Upper bound? ");
int upperBound = Integer.valueOf(scanner.nextLine());
ArrayList<Integer> list = new ArrayList<>();
try(Scanner fileReader = new Scanner(Paths.get(file))){
while(fileReader.hasNextLine()){
list.add(Integer.valueOf(fileReader.nextLine()));
}
}catch(Exception e){
System.out.println("Reading the file " + file + " failed.");
}
int numbers = 0;
for(int i = 0; i < list.size(); i++){
if(list.get(i) >= lowerBound && list.get(i) <= upperBound){
numbers++;
}
}
System.out.println("Numbers: " + numbers);
}
}```