public class Test_16 {
System.out.println("请输入a的值:");
int a = input.nextInt();
System.out.println("请输入b的值:");
int b = input.nextInt();
System.out.println("请输入c的值:");
int c = input.nextInt();
//判断
int temp;
if (a>b) {
temp = a;
a = b;
b = temp;
}
if (b>c) {
temp = c;
c = b;
b = temp;
}
if (a>b) {
temp = a;
a = b;
b = temp;
}
System.out.println(a+","+b+","+c);
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);System.out.println("请输入a的值:");
int a = input.nextInt();
System.out.println("请输入b的值:");
int b = input.nextInt();
System.out.println("请输入c的值:");
int c = input.nextInt();
//判断
int temp;
if (a>b) {
temp = a;
a = b;
b = temp;
}
if (b>c) {
temp = c;
c = b;
b = temp;
}
if (a>b) {
temp = a;
a = b;
b = temp;
}
System.out.println(a+","+b+","+c);
}
}
本文提供了一个使用Java编写的简单示例程序,该程序通过用户输入三个整数并使用选择排序的方法来实现数值从小到大的排序输出。通过这个例子,读者可以了解到如何在Java中使用Scanner类读取用户输入,以及如何通过简单的选择排序算法实现数值排序。
3400

被折叠的 条评论
为什么被折叠?



