import java.i0.*;
String tempStr=null;
int temInt ;
try{
BufferedReader in=new BufferedReader(
new InputStreamReader(System.in));
tempStr=(String)in.readLine();
}catch(IOException e){
//do noting
}
temInt = Integer.parseInt(temStr);
String tempStr=null;
int temInt ;
try{
BufferedReader in=new BufferedReader(
new InputStreamReader(System.in));
tempStr=(String)in.readLine();
}catch(IOException e){
//do noting
}
temInt = Integer.parseInt(temStr);
int i = System.in.readInt();
...
Integer.parseInt(s);如果抛出NumberFormatException则说明s不是一个合法的数字
import java.io.*;
public class trangle{
public static void main(String args[]){
int edge1;
int edge2;
int edge3;
Integer num=new Integer();
System.out.println("please input the first edge:");
edge1=num.intValue();
System.out.println("please input the second edge:");
edge2=num.intValue();
edge3=(edge1*edge1+edge2*edge2);
System.out.print("the thrid edge is that:");
System.out.println(edge3);
}
}
我的错在哪
import java.util.*;class test
{
public static void main(String args[])
{
int a ;
System.out.println("请输入一个整数:");
try
{
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
String strIn = is.readLine();
try{
a = Integer.parseInt(strIn);
}
catch(java.lang.NumberFormatException nex){
System.out.println("The input number is invalid,a = 10");
a = 10;
}
System.out.println("a = "+a);
}
}
}