-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.java
58 lines (52 loc) · 1.66 KB
/
Main.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
package L1_025;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @author zmj
* @create 2019/5/4
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
String a = "", b = "";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ') {
a = s.substring(0, i);
b = s.substring(i+1, s.length());
break;
}
}
// 检查a, b是否是正整数
boolean flagA = true, flagB = true;
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) < '0' || a.charAt(i) > '9') {
flagA = false;
}
}
for (int i = 0; i < b.length(); i++) {
if (b.charAt(i) < '0' || b.charAt(i) > '9') {
flagB = false;
}
}
if (flagA) {
int t = Integer.parseInt(a);
if (t > 1000 || t < 1) flagA = false;
}
if (flagB) {
int t = Integer.parseInt(b);
if (t > 1000 || t < 1) flagB = false;
}
if (flagA && flagB) {
int res = Integer.parseInt(a) + Integer.parseInt(b);
System.out.println(a + " + " + b + " = " + res);
} else if (flagA && !flagB) {
System.out.println(a + " + ? = ?");
} else if (!flagA && flagB) {
System.out.println("? + " + b + " = ?");
} else {
System.out.println("? + ? = ?");
}
}
}