我有以下代码:
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
}
我想知道,是否有可能将println放在一个循环中,从而将num1依次增加到num2和num3?我知道在我的情况下,我应该只使用串联而不是循环。但是我只是想知道是否想尝试大数字,是否可以在循环中更改变量的名称(将num1和num2和...中的“ 1”增加为“ 2”,依此类推)?还是不是,我必须坚持并置?
谢谢。