0

I have this following code:

Scanner scan = new Scanner(System.in);
        System.out.print("Enter number 1: ");
        int num1 = scan.nextInt();
        System.out.print("Enter number 2: ");
        int num2 = scan.nextInt();
        System.out.print("Enter number 3: ");
        int num3 = scan.nextInt();

        if (num1 < num2 && num2 < num3) { // Checks if the numbers are in increasing order

            System.out.println("Increasing: " + num1 + num2 + num3); // Prints them in increasing order
            Logger.getGlobal().info("\n\nThis step works!"); // If 3rd is highest, 2nd is mid and 1st is lowest
        }

I was wondering, is it possible to put the println in a loop such that it increases num1 to num2 then num3? I know that in my case I should just use the concatenation instead of loop. But I was just curious if I wanted to try big numbers, was it possible to change the names of variable (increase "1" to "2" and so on in num1 and num2 and ...) in a loop? Or is it not and I have to stick with concatenation?

Thanks.

John Cena
  • 29
  • 1
  • 4
  • 3
    Why not use an `int` array? arr[0], arr[1] etc. – Scary Wombat Oct 15 '20 at 00:38
  • Java does not allow for dynamic naming of variables, and it's really not needed since variable names don't have as much importance as many newbies assume that they have. References are the key much more so than variable names. And yes, use either an array or ArrayList for such a situation. – DontKnowMuchBut Getting Better Oct 15 '20 at 00:41

0 Answers0