[Java/Python]输出两数中的最小数 one-liner

 

 

Java

import java.util.Scanner;
public class compare
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        System.out.println("input your first number: ");
        int a = scan.nextInt();
        System.out.println("input your second number: ");
        int b = scan.nextInt();
        System.out.printf("the smaller number is %d.%n", a < b ? a : b);
    }
}

 

输出的结果可以是:

input your first number: 
56
input your second number: 
-9
the smaller number is -9.

 

 

Python:

a = int(input("input your first number: \n"))
b = int(input("input your second number: \n"))
print(f"the smaller number is {a if a < b else b}")

#或者:
# print(f"the smaller number is {min(a, b)}")

 

posted @ 2020-05-29 08:57  profesor  阅读(615)  评论(0编辑  收藏  举报