package hey; import java.util.Scanner; public class Specific_size { public static void main(String[] args) { //輸(1)輸入三個整數x,y,z,請把這三個數由小到大輸出。 //我們想辦法把最小的數放到x上, //先將x與y進行比較,如果x>y則將x與y的值進行交換, //然後再用x與z進行比較,如果x>z則將x與z的值進行交換,這樣能使x最小。 //輸(1)輸入三個整數x,y,z,請把這三個數由小到大輸出。 System.out.println("請輸入三整數,以空格分開:"); Scanner scanner=new Scanner(System.in); int a =scanner.nextInt(); int b =scanner.nextInt(); int c =scanner.nextInt(); scanner.close(); int temp = 0; if(a>b) { temp=b; b=a; a=temp; } if(b>c) { temp=b; b=c; c=temp; } if(a>b) { temp=b; b=a; a=temp; } System.out.println(a+" "+b+" "+c); } }
留言
張貼留言