-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleHelper.java
More file actions
35 lines (30 loc) · 939 Bytes
/
Copy pathConsoleHelper.java
File metadata and controls
35 lines (30 loc) · 939 Bytes
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ConsoleHelper {
private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
public static void writeMessage(String message){
System.out.println(message);
}
public static void writeError(String message){
System.err.println(message);
}
public static String readString(){
while (true) {
try{
return bufferedReader.readLine();
}catch (IOException e){
ConsoleHelper.writeError(e.getMessage());
}
}
}
public static int readInt(){
while (true) {
try{
return Integer.parseInt(readString());
}catch (NumberFormatException e){
ConsoleHelper.writeError(e.getMessage());
}
}
}
}