输入任意数排序

date: 2018/1/18 14:39:47


2018年JAVA基础节课考试—本人错误集合



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package android.xiaolan.paixu.tools;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static int a, b, c, max, mix;
public static void main(String[] args) {
Run1();
Run2();
Run3();
}
private static void Run3() {
System.out.println("第一个数");
a = sc.nextInt();
System.out.println("第二个数");
b = sc.nextInt();
System.out.println("第三个数");
c = sc.nextInt();
// 拿到最大值
if (a > b) {
max = a;
} else {
max = b;
}
if (max > c) {
} else {
max = c;
}
// 拿到最小值
if (a < b) {
mix = a;
} else {
mix = b;
}
if (mix < c) {
} else {
mix = c;
}
// 输出最小
System.out.println(mix);
// 输出中间的值
if (max == a) {
if (b > c) {
System.out.println(b);
} else {
System.out.println(c);
}
}
// 输出中间的值
if (max == b) {
if (a > c) {
System.out.println(a);
} else {
System.out.println(c);
}
}
// 输出中间的值
if (max == c) {
if (a > b) {
System.out.println(a);
} else {
System.out.println(b);
}
}
// 输出最大值
System.out.println(max);
}
private static void Run2() {
System.out.println("第一个数");
a = sc.nextInt();
System.out.println("第二个数");
b = sc.nextInt();
System.out.println("第三个数");
c = sc.nextInt();
for (int i = 0; i < 2; i++) {
if (a > b) {
int max = a;
a = b;
b = max;
}
if (b > c) {
int max = b;
b = c;
c = max;
}
}
System.out.println(a + "\n" + b + "\n" + c);
}
private static void Run1() {
int a[] = new int[3];
for (int i = 0; i < a.length; i++) {
System.out.println("输入第" + (i + 1) + "个数");
// 循环输入值 赋值数组
a[i] = sc.nextInt();
}
// 排序
Arrays.sort(a);
for (int i = 0; i < a.length; i++) {
// 输出排序
System.out.println(a[i]);
}
}
}

文章目录
  1. 1. date: 2018/1/18 14:39:47