高手们看看,我把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();
}
}
解决方案 »
- ArrayList排序问题
- java如何将时间戳转换为时间字符串?
- Tomcat重启后log4j不打印日志
- 怎么第二次checker.isAlive()还是false
- 关于JSP调用JAVABEAN的问题?
- 如何判断IP地址是否在一个地址段内
- 大家谈谈对反射的理解
- 用System.in.read()可以执行的程序用System.in.readline()就不能执行
- 各位看看这是怎么回事
- java国际化问题。为什么我的日文全变成方块。详情见内。谢谢
- 程序在Myeclipse中可以运行,打包后不能运行,cmd下也不能运行,这是怎么回事儿啊?
- 【急】java.net.SocketException问题
请输入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.