用java编写代码,从键盘输入三个整数,从小到大排序后输出
时间: 2023-05-27 11:04:32 浏览: 180
```java
import java.util.Scanner;
public class Sort{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[] nums = new int[3];
System.out.print("请输入三个整数:");
for(int i=0; i<3; i++){
nums[i] = input.nextInt();
}
for(int i=0; i<3-1; i++){
for(int j=0; j<3-i-1; j++){
if(nums[j]>nums[j+1]){
int temp = nums[j];
nums[j] = nums[j+1];
nums[j+1] = temp;
}
}
}
System.out.print("从小到大排序后的结果为:");
for(int i=0; i<3; i++){
System.out.print(nums[i] + " ");
}
}
}
```
阅读全文