1. 程式人生 > >計算a+b的和

計算a+b的和

每行包行兩個整數a和b

對於每行輸入對應輸出一行a和b的和
輸入
1 5
輸出
6

JAVA程式碼:

(一)

import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            int a = input.nextInt();
            int b = input.nextInt();
            int result = a+b;
            System.out.println(result);
        }
    }
}
(二)
import java.io.*;
public class Main{ 
public static void main(String[]args)throws Exception {
 BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
 String line =null;
 while((line=bu.readLine())!=null){ 
String []str=line.split(" +"); 
int a=Integer.parseInt(str[0]); 
int b=Integer.parseInt(str[1]); 
System.out.println(a+b); 
} bu.close();
 }}
(三)
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
    	add();
    }
    public static void add(){
    	Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int i = in.nextInt();
        	int j = in.nextInt();
            int s = 0;
            s = i + j;
          System.out.println(s);
            
        }
	}
    
}