-
Notifications
You must be signed in to change notification settings - Fork 1
/
IOMethods.java
executable file
·185 lines (155 loc) · 2.99 KB
/
IOMethods.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* Librarian Assistant Pro - Version 1.7
* Class: IB IO Methods
* Copyright © IB Organization
* Duties:
* Validating the input data
* The class is acquired from IB Booklet
* Creation Date: December 2008
*/
class IOMethods
{
public static void output(String info)
{
System.out.println(info);
}
public static void output(char info)
{
System.out.println(info);
}
public static void output(byte info)
{
System.out.println(info);
}
public static void output(int info)
{
System.out.println(info);
}
public static void output(long info)
{
System.out.println(info);
}
public static void output(double info)
{
System.out.println(info);
}
public static void output(boolean info)
{
System.out.println(info);
}
//APPENDIX 2
//© International Baccalaureate Organization 2004 101
public static String input(String prompt)
{
String inputLine = "";
System.out.print(prompt);
try
{
inputLine = (new java.io.BufferedReader(
new java.io.InputStreamReader(System.in))).readLine();
}
catch (Exception e)
{
String err = e.toString();
System.out.println(err);
inputLine = "";
}
return inputLine;
}
public static String inputString(String prompt)
{
return input(prompt);
}
public static String input()
{
return input("");
}
public static int inputInt()
{
return inputInt("");
}
public static double inputDouble()
{
return inputDouble("");
}
public static char inputChar(String prompt)
{
char result=(char)0;
try
{
result=input(prompt).charAt(0);
}
catch (Exception e)
{
result = (char)0;
}
return result;
}
public static byte inputByte(String prompt)
{
byte result=0;
try
{
result=Byte.valueOf(input(prompt).trim()).byteValue();
}
catch (Exception e)
{
result = 0;
}
return result;
}
public static int inputInt(String prompt)
{
int result=0;
try
{
result=Integer.valueOf(input(prompt).trim()).intValue();
}
catch (Exception e)
{
result = 0;
}
return result;
}
public static long inputLong(String prompt)
{
long result=0;
try
{
result=Long.valueOf(input(prompt).trim()).longValue();
}
catch (Exception e)
{
result = 0;
}
return result;
}
public static double inputDouble(String prompt)
{
double result=0;
try
{
result=Double.valueOf(input(prompt).trim()).doubleValue();
}
catch (Exception e)
{
result = 0;
}
return result;
}
//APPENDIX 2
//102 © International Baccalaureate Organization 2004
public static boolean inputBoolean(String prompt)
{
boolean result=false;
try
{
result=Boolean.valueOf(input(prompt).trim()).booleanValue();
}
catch (Exception e)
{
result = false;
}
return result;
}
//=========== end IBIO =======================================
}