题目描述
算法1
(Scanner)
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
System.out.println(a+b);
}
}
算法2
(BufferedReader)
import java.io.*;
public class Main{
public static void main(String[]args)throws IOException{
BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
String[]str=cin.readLine().split(" ");
int[]arr=new int[2];
for(int i=0;i<arr.length;i++){
arr[i]=Integer.parseInt(str[i]);
}
System.out.println(arr[0]+arr[1]);
}
}
结论:
在做题的时候用BufferedReader更好!