-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminal.java
More file actions
81 lines (54 loc) · 1.5 KB
/
Copy pathTerminal.java
File metadata and controls
81 lines (54 loc) · 1.5 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Created on 29.10.2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
/**
* @author kratzer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
import java.io.*;
public class Terminal {
public static String getString(String prompt) {
if (!prompt.equals("")) put(prompt);
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
try {
return input.readLine();
} catch (Exception e) {
return "";
}
}
public static int getInt(String prompt) {
int resultat = 0;
try {
resultat = Integer.parseInt(getString(prompt));
} catch (Exception e) {
put("Bitte eine ganze Zahl (Betrag < 2E9) eingeben!");
resultat = getInt(prompt);
}
return resultat;
}
public static double getDouble(String prompt) {
double resultat = 0.0;
try {
resultat = Double.parseDouble(getString(prompt));
} catch (Exception e) {
put("Bitte eine ordentliche Gleitkommazahl eingeben!");
resultat = getDouble(prompt);
}
return resultat;
}
public static void put(String s) {
System.out.println(s);
}
public static void put(int s) {
System.out.println(s);
}
public static void put(double s) {
System.out.println(s);
}
}