System.in 
byte[] buf = new byte[1024];
byte chr = 0;
int count = 0;
while(chr != '\n'){
  chr = (byte)in.read();
  buf[count++] = chr;
}
String value = new String(buf);
int intValue = Integer.parseOf(value);

解决方案 »

  1.   

    我再说仔细一点吧,程序如下,可编译不对,哪里有错,还请各位指出
    import java.io.*;
    public class triangleclass{
      public static void main(String[] args){
        int sideA;
        System.out.print("请输入sideA的长度:");
          try{
              sideA=(int)System.in.read();
              System.out.print("第一条边的长度:"+sideA);
          }catch(IOException e){};
    }
    }
    结果确为:
    请输入sideA的长度:5
    第一条边的长度:53
      

  2.   

    编译不对还能执行?            sideA=(int)System.in.read();
                char c = (char) sideA;
                System.out.print("第一条边的长度:" + c);
      

  3.   

    sideA=(int)System.in.read();
    这样取得是ascii码,所以是53,所以先当字符处理比如char什么的
      

  4.   

    sideA=(int)System.in.read();
    这样得到的是ascii码
      

  5.   

    我知道得到是ASCII吗,可是怎样解决呢,请告知
      

  6.   

    import java.io.*;
    public class SystemIn{
      public static void main(String args[]){
        try{
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          String msg = in.readLine();
          /* 可以从命令行中得到数值,放到变量中*/
          int value = Integer.parseInt(msg);
          in.close();
        }catch(IOException e){
          e.printStackTrace();
        }
      }
    }
      

  7.   

    谢谢楼上!还有一点疑问
     BufferedReader in = new BufferedReader(new InputStreamReader(System.in)
    这句话是关键,可我不明白的是BufferedReader和InputStreamReader都是character流中reader类族的,是同级关系,可为什么是这样调用呢,能不能就这句话做一个解释,谢谢。
      

  8.   

    System.in 是字节流
    InputStreamReader  是个转换类,把字节流转换为字符流。
    BufferedReader  是字符流。
      

  9.   

    String str=JOptionPane.showInputDialog("you name?");也可以转换int
      

  10.   

    import java.io.*;
    public class test{
      public static void main(String args[]){
        for(int i=0;i<3;i++){
          try{
            System.out.print("请输入"+i+"个数值:");
            BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
            String msg=in.readLine();
            /* 可以从命令行中得到数值,放到变量中*/
            int value = Integer.parseInt(msg);
            System.out.print("第"+i+"条边的长度:"+value);
          }catch(IOException e){e.printStackTrace();}
        }
      }
    }
    这样得出的只是三个值,并不能带入到变量中,于是import java.io.*;
    public class test{
      public static void main(String args[]){
        for(int i=0;i<3;i++){
          try{
            System.out.print("请输入"+i+"个数值:");
            BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
            String msg=in.readLine();
            /* 可以从命令行中得到数值,放到变量中*/
            int value[i]= Integer.parseInt(msg);*/这句话不明白是什么意思?
            System.out.print("第"+i+"条边的长度:"+value[i]);
          }catch(IOException e){e.printStackTrace();}
        }
      }
    }想得到键盘读入3个值,分别存入value0、value1、value2
    可是程序不能通过编译,请指点