import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); System.out.println(); if (a >= b) { if (b >= c) { System.out.printf("%d >= %d >= %d", a, b, c); } else if (a >= c) { System.out.printf("%d >= %d >= %d", a, c, b); } else { System.out.printf("%d >= %d >= %d", c, a, b); } } else { if (a >= c) { System.out.printf("%d >= %d >= %d", b, a, c); } else if (b >= c) { System.out.printf("%d >= %d >= %d", b, c, a); } else { System.out.printf("%d >= %d >= %d", c, b, a); } } } }
另外一種解法:
import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); System.out.println(); int max = a; int min = a; if (b > max) { max = b; } if (c > max) { max = c; } if (b < min) { min = b; } if (c < min) { min = c; } System.out.printf("%d >= %d >= %d", max, a + b + c - max - min, min); } }
謝謝
回覆刪除