高手们看看,我把System.out.println("请输入y:"); 注释掉它就报错了,什么原因啊?第一次发帖还望勿喷import java.io.*;
class Dian
{
int x;
int y;
public Dian()throws Exception
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("请输入x:");
String s=br.readLine();
x=Integer.parseInt(s);
//System.out.println("请输入y:");
s=br.readLine();
y=Integer.parseInt(s);
}
void show()
{
System.out.println("("+x+","+y+")");
}
public static void main(String args[])throws Exception
{
Dian dian1=new Dian();
dian1.show();
}
}
class Dian
{
int x;
int y;
public Dian()throws Exception
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("请输入x:");
String s=br.readLine();
x=Integer.parseInt(s);
//System.out.println("请输入y:");
s=br.readLine();
y=Integer.parseInt(s);
}
void show()
{
System.out.println("("+x+","+y+")");
}
public static void main(String args[])throws Exception
{
Dian dian1=new Dian();
dian1.show();
}
}
请输入x: 3
5
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Dian.<init>(Dian.java:15)
at Dian.main(Dian.java:23) Process completed.
一执行就这样了
我运行的效果如下:
run:
请输入x:
3
请输入y:
4
(3,4)
成功生成(总时间:17 秒)我用的netbeans 一般小程序懒得开myeclipse了 太慢
(下面是注释过运行出来的)
请输入x:
3
5
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Dian.<init>(Dian.java:15)
at Dian.main(Dian.java:23) Process completed.