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
| import java.io.*;
public abstract class EasyIn
{
static String s = new String();
static byte[] b = new byte[512];
static int bytesRead = 0;
public static int getInt()
{
int i = 0;
boolean ok = false;
while(!ok)
{
try
{
bytesRead = System.in.read(b);
s = new String(b,0,bytesRead-1);
i = Integer.parseInt(s.trim());
ok = true;
}
catch(NumberFormatException e)
{
System.out.println("Make sure you enter an integer");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return i;
} |
Partager