import java.io.*;
class  abbad
{
public static void main(String[] args) 
{
try
{
    int n=(int)System.in.read();//这句可以吗
    
}
catch(IOException e) {}
System.out.println("输入的n的值为:"+n);
}
}

解决方案 »

  1.   

    这样读的是ascII码,用Scanner的nextInt来读
      

  2.   

    nextInt(int radix) 
              将输入信息的下一个标记扫描为一个 int。
      

  3.   

    import java.util.Scanner; 
    class  abbad 

    public static void main(String[] args)  
    {
    try 

    //int n=(int)System.in.read();//这句可以吗
         Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    System.out.println("输入的n的值为:"+n);

    catch(Exception e) {} 
     

    }
      

  4.   

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;/**
     *
     * @author zm
     */
    public class Main {    /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws IOException 
        {
            // TODO code application logic here
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String value = br.readLine();
            int i = -1;
            try
            {
                i = Integer.parseInt(value);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            System.out.println("result: " + i);
            
        }}