import java.io.*;
import java.util.Scanner;
public class C {
public static void main(String []args) throws IOException
{ String x1,x2;
    int sum=0;
    
  System.out.print("BufferedReader方法\ninput two number:");

    //BufferedReader对象只将回车看作输入结束,得到的字符串
    BufferedReader myReader=new BufferedReader(new InputStreamReader(System.in));
    x1=myReader.readLine();
    x2=myReader.readLine();
    int a=Integer.parseInt(x1);
    int b=Integer.parseInt(x2);
    sum=a+b;
    System.out.printf("Sum=%d",sum/2);

    System.out.println("\n\nScanner 方法");
    Scanner sc=new Scanner(System.in);
    int a1,b1;
    a1=sc.nextInt();  

    //Scanner对象把回车,空格,tab键都看作输入结束,直接用sc.next()得到的是字符串形式
    b1=sc.nextInt();
    System.out.print("sum="+(a1+b1)/2);    
  }
}

BufferedReader方法-----Scanner方法

相关文章:

  • 2021-06-30
  • 2021-12-15
  • 2021-07-09
  • 2021-12-30
  • 2021-08-05
  • 2022-01-18
  • 2022-01-09
  • 2021-06-03
猜你喜欢
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-06-05
  • 2021-05-21
相关资源
相似解决方案