java输入三个整数x,y,z,请把这三个数由小到大输出。
时间: 2023-04-13 10:01:26 浏览: 85
可以使用Java语言编写一个程序来实现这个功能,具体代码如下:
```
import java.util.Scanner;
public class SortNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入三个整数x,y,z:");
int x = input.nextInt();
int y = input.nextInt();
int z = input.nextInt();
int temp;
if (x > y) {
temp = x;
x = y;
y = temp;
}
if (x > z) {
temp = x;
x = z;
z = temp;
}
if (y > z) {
temp = y;
y = z;
z = temp;
}
System.out.println("由小到大输出:" + x + " " + y + " " + z);
}
}
```
运行程序后,会提示用户输入三个整数x、y、z,然后通过比较大小,将它们从小到大排序,并输出结果。