通过System.in.read()读入的是字符,所以输入1的时候值是49
转成数字就可以了i=System.in.read()-48;

解决方案 »

  1.   


    BufferedReader stdin = new 
    BufferedReader(new 
    InputStreamReader(System.in));

    i=Integer.parseInt(stdin.readLine());
      

  2.   

    呵呵~,楼上的说的不完全对呀,
    如果输入的是498呢,3位数捏?
    -----这段程序应该是一段循环,按回车建(或自己确定的特定键)表示输入计数值(N)过程结束。
      初始化过程值为0
      while () {
        刚输入的数=System.in.read()-48
        过程值=过程值×10 +刚输入的数
        错误处理:如果输入的是非数字,循环退出       
      }大致思想应该始这样地,你可以将它补完。
      

  3.   

    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);     
      }
    }
      

  4.   

    同意楼上地,要用BufferedReader包装,然后用readLine来读取你输入的数据
      

  5.   

    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);     
      }
    }===============好
      

  6.   

    好像可以直接强制转换类型的吧?
      try{
            character=(char)System.in.read();
     }catch(IOException e){}System.in.read()读到的是char?是int?