【练习】
题目要求:
* 编写一个程序,让用户输入3个整数,
* 按照从小到大的顺序,将三个整数输出。
* (注意输入输出时要对用户有提示信息)
import java.util.Scanner;
public class sortnum {
public static void main(String[] args) {
System.out.println("请输入3个整数:");
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个数字的值:");
int a = scanner.nextInt();
System.out.println("请输入第二个数字的值:");
int b = scanner.nextInt();
System.out.println("请输入第三个数字的值:");
int c = scanner.nextInt();
if(a > b){
int t = a;
a = b;
b = t;
}
if(a > c){
int t = a;
a = c;
c = t;
}
if(b> c){
int t= b;
b= c;
c= t;
}
System.out.println("三个数字从小到大的排列为:"+a+","+b+","+c);
scanner.close();
}
}