java 求两个数最大值

 

//find greatest among two numbers

import java.util.Scanner;

public class Numbers {

    public static void main(String[] args) {
        int num1, num2;
        Scanner ip = new Scanner(System.in);
        System.out.print("Enter num1: ");
        num1 = ip.nextInt();
        System.out.print("Enter num2: ");
        num2 = ip.nextInt();
        if (num1 > num2)
            System.out.println(num1 + " is greater that " + num2);
        else if (num2 > num1)
            System.out.println(num2 + " is greater that " + num1);
        else
            System.out.println("Both are same");

        ip.close();
    }

}



OUTPUT:
Enter num1: 35
Enter num2: 45
45 is greater that 35

 

你可能感兴趣的:(java 求两个数最大值)