我想从键盘输入两个数,然后存在int a;和int b;中.应该怎么写啊?能更详细的讲下System.in的用法更好啊

解决方案 »

  1.   

    import java.io.*; 
    public class Test

    public static void main(String[] args) 

    FileInputStream fileIn = null; 
    FileOutputStream fileOut = null; 
    PrintWriter pw = null; 
    BufferedReader br = null; 
    try{ 
    fileIn = new FileInputStream(new File(args[0])); 
    fileOut = new FileOutputStream(new File(args[1])); br = new BufferedReader(new InputStreamReader(fileIn)); 
    pw = new PrintWriter(new OutputStreamWriter(fileOut)); String s = null; 
    while((s = br.readLine())!=null) 

    System.out.println(s); 
    s = s.replaceAll(",",",\n"); 
    pw.write(s); 


    catch(ArrayIndexOutOfBoundsException e) 
    {e.printStackTrace();} 
    catch(IOException e) 
    {e.printStackTrace();} 
    finally{ 
    try 

    pw.flush(); br.close(); pw.close(); 

    catch (IOException e) 

    e.printStackTrace(); 
    } } 


      

  2.   

    System.in属于Java的标准输入流,因为输入流可以包括一个文件,键盘输入,更或是一个其他的输入流等,System.in就属于控制台输入流,键盘输入是一种System.in流
      

  3.   

    简单把System.in包装到就行了.
    多看API
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
    String inputStr = br.readLine(); 
     
      

  4.   

    你把键盘看着是文件,
    和文件一样的操作.
    帮我看看我的贴:
    AWT-EventQueue-0 "是个什么东西 
     50  buyiwangzi 刚发的.
      

  5.   

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;public class TestExample {
    public static void main(String []args) throws IOException
    {
      int a,b;
      String str;
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      str=br.readLine();
      a=Integer.parseInt(str);
      str=br.readLine();
      b=Integer.parseInt(str);
      System.out.println("a="+a+" "+"b="+b);
    }
    }
      

  6.   

    只能是把输入的数先存成String类型?然后用Integer.parseInt或者Double.parseDouble等再把它转换过来吗?比如我我只让他输入数字,输入别的我报错,然后就把输入的直接存在int类型中?能不能这样???
      

  7.   


    import java.util.Scanner;public class Stdin { public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    String s=sc.next();
    System.out.println("a+b="+(a+b));
    System.out.println(s);
    }}
      

  8.   

    多看API 手册   很有帮助
      

  9.   

    System.in 是 Scanner包中的方法 主要用于从键盘上读取数据
    例如:
         Scanner sc=new Scanner(System.in);
        int m=sc.next.Int();
             System.out.println(m);