forked from hacktoberfest17/programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.java
More file actions
46 lines (40 loc) · 1.14 KB
/
Input.java
File metadata and controls
46 lines (40 loc) · 1.14 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Keyboard input functions. Doesn't validate user's input.
* Adapted code from university assignments.
* @author Professor Delamaro
*/
public class Input {
static InputStreamReader isr = new InputStreamReader(System.in);
static BufferedReader br = new BufferedReader(isr);
/**
* Read a string typed by the user until \n
* @return string typed by the user
* @throws IOException
*/
public static String readString() throws IOException {
String x;
x = br.readLine();
return x;
}
/**
* Read a string and convert it to int. Doesn't validate user's input.
* @return value typed by the user
* @throws IOException
*/
public static int readInt() throws IOException {
String x = readString();
return Integer.parseInt(x);
}
/**
* Read a string and convert it to double. Doesn't validate user's input.
* @return value typed by the user
* @throws IOException
*/
public static double readDouble() throws IOException {
String x = readString();
return Double.parseDouble(x);
}
}