码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-05-29 09:18:03      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:string   import   lin   lse   else   tin   NPU   oid   nbsp   

 

 

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)}")

 

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

标签:string   import   lin   lse   else   tin   NPU   oid   nbsp   

原文地址:https://www.cnblogs.com/profesor/p/12985429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!