34 输入3个数a,b,c,按大小顺序输出
2023-10-21 本文已影响0人
北极的大企鹅
题目:输入3个数a,b,c,按大小顺序输出
1 public class _034Sorting {
2
3 public static void main(String[] args) {
4 sorting();
5 }
6
7 private static void sorting() {
8 Scanner scanner = new Scanner(System.in);
9 System.out.println("请输入3个整数:");
10
11 int a = scanner.nextInt();
12 int b = scanner.nextInt();
13 int c = scanner.nextInt();
14 int temp = 0;
15
16 if (a < b) {
17 temp = a;
18 a = b;
19 b = temp;
20 }
21
22 if (a < c) {
23 temp = a;
24 a = c;
25 c = temp;
26 }
27
28 if (b < c) {
29 temp = b;
30 b = c;
31 c = temp;
32 }
33
34 System.out.println("三个数从大到小的顺序输出是:");
35 System.out.println(a + "," + b + "," + c);
36 }
37
38 }