一个超级简单的问题. 通过System.in.read()读入的是字符,所以输入1的时候值是49转成数字就可以了i=System.in.read()-48; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); i=Integer.parseInt(stdin.readLine()); 呵呵~,楼上的说的不完全对呀,如果输入的是498呢,3位数捏?-----这段程序应该是一段循环,按回车建(或自己确定的特定键)表示输入计数值(N)过程结束。 初始化过程值为0 while () { 刚输入的数=System.in.read()-48 过程值=过程值×10 +刚输入的数 错误处理:如果输入的是非数字,循环退出 }大致思想应该始这样地,你可以将它补完。 import java.io.*;public class test2{ public static void main(String arg[]) throws IOException { int i; int j; int m=0; BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); i=Integer.parseInt(stdin.readLine()); for(j=0;j<=i;j++) { m=m+j; } System.out.print(m); }} 同意楼上地,要用BufferedReader包装,然后用readLine来读取你输入的数据 import java.io.*;public class test2{ public static void main(String arg[]) throws IOException { int i; int j; int m=0; BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); i=Integer.parseInt(stdin.readLine()); for(j=0;j<=i;j++) { m=m+j; } System.out.print(m); }}===============好 好像可以直接强制转换类型的吧? try{ character=(char)System.in.read(); }catch(IOException e){}System.in.read()读到的是char?是int? 我在整合hibernate和Spring时候报才错误,请大家帮我解决下! why? btnExport_java.lang.NullPointerException java默认浮点型是什么?double OR float? 问题程序 java语言中有让最小化窗口在任务栏闪烁的方法吗? 试试看,IBM招聘题 100分大奉送! 谈谈K-Java联盟 讨论java程序员的最佳工作地点。。。。。 求教:16进制文件转16位图像 新手在线等 请问哪里可以下载visibroker??(好的连接马上给分)
BufferedReader stdin = new
BufferedReader(new
InputStreamReader(System.in));
i=Integer.parseInt(stdin.readLine());
如果输入的是498呢,3位数捏?
-----这段程序应该是一段循环,按回车建(或自己确定的特定键)表示输入计数值(N)过程结束。
初始化过程值为0
while () {
刚输入的数=System.in.read()-48
过程值=过程值×10 +刚输入的数
错误处理:如果输入的是非数字,循环退出
}大致思想应该始这样地,你可以将它补完。
public class test2{
public static void main(String arg[]) throws IOException
{
int i;
int j;
int m=0; BufferedReader stdin = new
BufferedReader(new
InputStreamReader(System.in));
i=Integer.parseInt(stdin.readLine()); for(j=0;j<=i;j++)
{
m=m+j;
}
System.out.print(m);
}
}
public class test2{
public static void main(String arg[]) throws IOException
{
int i;
int j;
int m=0; BufferedReader stdin = new
BufferedReader(new
InputStreamReader(System.in));
i=Integer.parseInt(stdin.readLine()); for(j=0;j<=i;j++)
{
m=m+j;
}
System.out.print(m);
}
}===============好
try{
character=(char)System.in.read();
}catch(IOException e){}System.in.read()读到的是char?是int?