Sou a: Inici / Usuaris / jordifarrero / 2012-13 :: Entorns desenvolupament :: DAW2 Tarda / Codis exemple / Codi simple Java 1 - in out array readline

Codi simple Java 1 - in out array readline

int a = 0;
String inputa;


int[] myarr=new int[3];
myarr[1]=3;


BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter a number: ");
try
{
inputa = stdin.readLine();
a = Integer.parseInt(inputa);
}
catch(IOException ioex)
{
System.out.println("Input error");
System.exit(1);
}
catch ( NumberFormatException e)
{
System.out.println (e.getMessage() + " is not a valid format for aninteger.");
System.exit(1);
}

if(a==3) System.out.println ("Number 3!!!: " + a);

System.out.println ("You entered: " + a);