Java两种读取输入的方式

  1. 使用Scanner类
  2. 使用BufferReader类
public class InputMethod {
    public static void main(String args[]) throws IOException {
        //1. use Scanner
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        float b = sc.nextFloat();
        String c = sc.next();
        //2. use BufferedReader
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String str = bf.readLine();
        int s = bf.read();
    }
}

你可能感兴趣的:(Java两种读取输入的方式)