-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.java
More file actions
60 lines (53 loc) · 1.23 KB
/
Action.java
File metadata and controls
60 lines (53 loc) · 1.23 KB
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
package process;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Action extends FormatError {
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 入力
String action() {
String in = "";
System.out.print(" > ");
try {
in = br.readLine();
// 途中終了
if ("exit".equals(in)) {
System.out.println("*-------------終了--------------------*");
System.exit(1);
}
// 入力なしは再帰呼び出し
if ("".equals(in)) {
System.out.print("入力してください");
in = action();
} else if (in.length() > 1) {
// 1文字のみ
System.out.print("一文字のみ有効");
in = action();
} else {
// 数値変換
if (NumFormatError(in)) {
// 数値変換できない場合
System.out.print("無効な文字");
in = action();
}
}
} catch (IOException e) {
System.out.println("入力エラー >" + e);
}
return in;
}
// user入力やり直し
boolean enter() {
try {
String in = br.readLine();
if ("".equals(in)) {
return false;
} else {
return true;
}
} catch (IOException e) {
System.out.println("Error" + e);
}
return true;
}
}