我是新手,大家多多指教。一个问题:怎样读取一个从键盘输入的数啊?

解决方案 »

  1.   

    你不是吧,还没学到就慢慢学吧
    可以先去看下io方面的东西就知道了
    或者用util包里面的scanner
      

  2.   


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;class Test {
    public static void main(String[] args){
    int a;
    String str;
    try{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    str = br.readLine();
    a = Integer.parseInt(str);
    }
    catch(IOException e){
    e.printStackTrace();
    }
    }
    }
      

  3.   


    import java.util.*;
    public class Test{
        public static void main(String args[]) throws IOException{
            int num=0;
            Scanner str=new Scanner(System.in);
            num=str.nextInt();
            System.out.println(num);
        }
    }
      

  4.   

    public class Test {
        public static void main(String[] args) {
            int a;
            String str = javax.swing.JOptionPane.showInputDialog(null, "Please a number you who:");
            try {
                a = Integer.parseInt(str);
            }catch(Exception ex) {}
        }
    }
             
      

  5.   


    LZ可以看看下面的代码:
    import java.io.*;
    public class ConsoleInput {
    public static void main(String [] args){
    InputStreamReader rin=new InputStreamReader(System.in);
    BufferedReader in=new BufferedReader(rin);
    String s=null;
    try{
    while(!((s=in.readLine()).equalsIgnoreCase("end")))//输入字符,若是end结束。
       System.out.println(s);  //字符回显
    }
    catch(IOException e){
    e.printStackTrace();
    }
    }
    }
      

  6.   


    Scanner类在util包下!
    import java.util.Scanner;
    Scanner str=new Scanner(System.in);
    num=str.nextInt();//整型  str.next();//字符串的输入  str.nextDouble();//浮点数!
    System.out.println(num);
      

  7.   

    教你用个最简单的方法,直接在控制台里输入吧,
    String args[]这个args存的就是你在dos中输入字符串
    比如java class nihao wohao 
    args[0]就是nihao
    args[1]就是wohao
    试试用这个方法打印Hello World!