-
Notifications
You must be signed in to change notification settings - Fork 0
/
In.java
74 lines (64 loc) · 1.44 KB
/
In.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.*;
import java.text.*;
public class In
{
static InputStreamReader r = new InputStreamReader(System.in);
static BufferedReader br = new BufferedReader(r);
// Read a String from standard system input
public static String getString()
{
try
{
return br.readLine();
}
catch (Exception e)
{
return "";
}
}
// Read a Number as a String from standard system input
// Return the Number
public static Number getNumber()
{
String numberString = getString();
try
{
numberString = numberString.trim().toUpperCase();
return NumberFormat.getInstance().parse(numberString );
}
catch (Exception e)
{
// If any exception occurs, just return zero
return new Integer(0);
}
}
// Read an int from standard system input
public static int getInt ()
{
return getNumber().intValue();
}
// Read a long from standard system input
public static long getLong ()
{
return getNumber().longValue();
}
// Read a float from standard system input
public static float getFloat ()
{
return getNumber().floatValue();
}
// Read a double from standard system input
public static double getDouble ()
{
return getNumber().doubleValue();
}
// Read a char from standard system input
public static char getChar ()
{
String s = getString();
if (s.length() >= 1)
return s.charAt(0);
else
return '\n';
}
}