初学JAVA问个输入的问题. Integer.parseInt("1234");,注意,如果包含有非數字字符,會丟出異常,捕捉一下就行了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try{byte buffer[]=new byte[30];System.in.read(buffer);String strBuffer=new String(buffer);System.out.println(strBuffer);} catch(Exception ex) { ex.printStackTrace(); } int i = Integer.parseInt(strBuffer); new BufferedReader in=new BufferedReader(new InputStreamReader(System.in));while(true){String s=in.readLine();try{int tt=Integer.parseInt(s);}catch(Exception e){e.printStace();}} class InOutDemo{ public static void main(String args[])throws Exception { byte buffer[]=new byte[30]; System.in.read(buffer); String strBuffer=new String(buffer); System.out.println(strBuffer); int i=Integer.parseInt(strBuffer); System.out.println(strBuffer); }}谢谢大家,现在改成这样了,可我明明输入的是123,可为什么还是会出现异常呢? 在你的程序中使用了SYSTEM.IN,从中读取输入信息,但是你应该捕获IOException异常,把System.in.read(buffer);改为try {System.in.read(buffer);} catch(IOException e) {//处理异常的操作 } 你限制了byte buffer[] = new byte[30]输入了123,但内容却是123__________...'_'是空格试试int i = Integer.parseInt(strBuffer.trim()); 另外你还要捕获一个异常,就是你使用Integer.parseInt(strBuffer);的地方 异常呀,哦,这就把书上有关异常的那章看看.to Kick_hotdog(khd)你那样说应该是针对buffer这个字节数组可我已经把它转换成strBuffer这个字符串了应该不存在空的内容才对吧,不知道我这样理解对不对. 正在看有关异常的那章内容好多,那位大侠能写段完整的程序吗?要求很简单在程序里定义一个INT I,然后通过键盘输入给I附值. 今天突然发现的application程序的一个奇怪现象 既是列表又是树型的控件 用jsp 做计算器时 人民币200+ 求助java一简单进程问题 关于视频桢截取的问题,谢谢!! 窗口问题 如何对字符串加密解密?(des,md5等等都可以) 小弟是JAVA的初学者..希望和大家一起交流和学习....群号:13265465 java的数组是从零开始还是从壹开始的? 请教:java在unix/linux下的运行速度如何?还是像在windows下那么慢吗?比如jbiulder的linux版,速度如何?我没有试过,谢 ~~文档中的字符~~~疑问! 请教applet问题!
System.in.read(buffer);
String strBuffer=new String(buffer);
System.out.println(strBuffer);
}
catch(Exception ex)
{
ex.printStackTrace();
}
while(true){
String s=in.readLine();
try{int tt=Integer.parseInt(s);}catch(Exception e){e.printStace();}
}
{
public static void main(String args[])throws Exception
{
byte buffer[]=new byte[30];
System.in.read(buffer);
String strBuffer=new String(buffer);
System.out.println(strBuffer);
int i=Integer.parseInt(strBuffer);
System.out.println(strBuffer);
}
}
谢谢大家,现在改成这样了,可我明明输入的是123,可为什么还是会出现异常呢?
try {
System.in.read(buffer);
} catch(IOException e) {
//处理异常的操作
}
byte buffer[] = new byte[30]
输入了123,
但内容却是123__________...'_'是空格
试试int i = Integer.parseInt(strBuffer.trim());
to Kick_hotdog(khd)
你那样说应该是针对buffer这个字节数组可我已经把它转换成strBuffer这个字符串了应该不存在空的内容才对吧,不知道我这样理解对不对.