Summation (Java)

This question requires to read in several pairs of integers a and b, and then output their sum.

Input format:
Give a pair of integers a and b in one line. The following input sample has only two pairs, and the actual test data may have multiple pairs of values.

Output format:
For each group of input, if the absolute value of a>1000, output |a|>1000, otherwise output the value of a+b.

Input example:
18 -299
1001 -9
-1001 8

Sample output:
-281
|a|>1000
|a|>1000

import java.util.Scanner;

public class Main {
    
    
    public static void main(String[] args) {
    
    
        Scanner sc=new Scanner(System.in);
        while (sc.hasNextInt()){
    
    
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (a>1000||a<-1000){
    
    
                System.out.println("|a|>1000");
            }else{
    
    
                System.out.println(a+b);
            }
        }
    }
}

Guess you like

Origin blog.csdn.net/weixin_51430516/article/details/115048327