用户输入三个整数,之后按照整数的大小从小到大输出
import java.util.Scanner;
class Exer1 {
public static void main(String[] args) {
//输出结果从大到小排序
Scanner scan = new Scanner (System.in);
System.out.println("请输入第一个整数:");
int num1 = scan.nextInt();
System.out.println("请输入第二个整数:");
int num2 = scan.nextInt();
System.out.println("请输入第二个整数:");
int num3 = scan.nextInt();
if (num1 > num2){
if (num3 >= num1){
System.out.println(num3 + "," + num1 + "," + num2 );
}else if (num3 <= num2){
System.out.println(num1 + "," + num2 + "," + num3 );
}else {
System.out.println(num1 + "," + num3 + "," + num2 );
}
}else{
if (num3 >= num2){
System.out.println(num3 + "," + num2 + "," + num1 );
}else if (num3 <= num1){
System.out.println(num2 + "," + num1 + "," + num3 );
}else{
System.out.println(num2 + "," + num3 + "," + num1 );
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/83353.html