import java.util.Scanner;
public class Exercise8 {
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
System.out.print("Enter three numbers:");
int num1 = input.nextInt();
int num2 = input.nextInt();
int num3 = input.nextInt();
if (num1 > num2) {
int temp = num1;
num1 = num2;
num2 = temp;
}
if (num2 > num3) {
int temp = num2;
num2 = num3;
num3 = temp;
}
if (num1 > num2) {
int temp = num1;
num1 = num2;
num2 = temp;
}
System.out.println("The sorted numbers are " + num1 + " " + num2 + " " + num3);
}
}
為什麼debug時只運行第一個if,然後就直接跳到輸出了
你的輸入是多少?後面兩個條件不滿足自然不執行。