I have a txt file with 5 integers, then from standard input if I entered 1 it will output 10 if I entered 3 it will output 30. I put mine in an array, I just want to know if its possible to not put it in an array and still output the same way.

number.txt
10 20 30 40 50

public static void main(String[] args) throws IOException {

        int num = 5;
        int[] numArray = new int [num];

        //Reads in 5 integers
        File tempo = new File ("number.txt");
        Scanner file = new Scanner(tempo);

        for( int i = 0; i < numArray.length; i++){
            numArray[i] = file.nextInt();
        }

If you don't put them in an array (or some other container eg ArrayList) then you would have to re-read the file for each user input, which would be a messy and inefficient solution.

Thank you for your response!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.