当前位置: 技术问答>java相关
这段代码怎么究竟哪里出错!?(在线等)
来源: 互联网 发布时间:2015-05-30
本文导语: public static void main (String[] args) { int inChar; System.out.println("Please enter a Character"); try { inChar=System.in.read(); System.out.print("U enter"+inChar); } catch(IOException e) { System.out.print("U enter a bad Character"); ...
public static void main (String[] args)
{
int inChar;
System.out.println("Please enter a Character");
try
{
inChar=System.in.read();
System.out.print("U enter"+inChar);
}
catch(IOException e)
{
System.out.print("U enter a bad Character");
}
}
从vj++上copy下来,运行时他说IOException出问题,可是我是照书上抄的,对过了,没错的!那么究竟哪里错了???
还有一个问题,就是我用vj++的Application Console来写java程序,怎么那个命令行窗口这么快就消失了?我还来不及看它就没了,就连简单的hello world也看不到,一定要把2000的命令行打开,然后找到那个java程序的目录,再去运行才会一直有,这是怎么会是啊?
{
int inChar;
System.out.println("Please enter a Character");
try
{
inChar=System.in.read();
System.out.print("U enter"+inChar);
}
catch(IOException e)
{
System.out.print("U enter a bad Character");
}
}
从vj++上copy下来,运行时他说IOException出问题,可是我是照书上抄的,对过了,没错的!那么究竟哪里错了???
还有一个问题,就是我用vj++的Application Console来写java程序,怎么那个命令行窗口这么快就消失了?我还来不及看它就没了,就连简单的hello world也看不到,一定要把2000的命令行打开,然后找到那个java程序的目录,再去运行才会一直有,这是怎么会是啊?
|
大哥,你这个程序里面并没有用到IO流方面的东西
所以捕捉异常根本捕捉不到IOException异常,等于
catch(IOException e)这句没有用,将它改为
catch(Exception e)就行
btw:你也太狠了,才1分……
呵呵
所以捕捉异常根本捕捉不到IOException异常,等于
catch(IOException e)这句没有用,将它改为
catch(Exception e)就行
btw:你也太狠了,才1分……
呵呵
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。