A + B Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 886499 Accepted Submission(s): 266845
Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
第一次写java,新学的hasnext(),感觉自己还不是太熟练
代码:
C
#include <stdio.h>
int main()
{
int A,B,sum;
while (scanf("%d %d",&A,&B) !=EOF)
{
sum=A+B;
printf("%d\n",sum);
}
}
JAVA
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
while(a.hasNextInt())
{
int A = a.nextInt();
int B = a.nextInt();
System.out.println(A+B);
}
}
}