求最大值(求最大值)

本题目要求读入2个整数A和B,然后输出两个数的最大值。

输入格式:
输入在一行中给出2个绝对值不超过1000的整数A和B。

输出格式:
对每一组输入,在一行中输出最大值。

输入样例:
在这里给出一组输入。例如:
18 -299

输出样例:
在这里给出相应的输出。例如:
18

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();
            System.out.println(a>b?a:b);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_51430516/article/details/115048363