编写java程序,输入三个整数x,y,z,请把这三个数由小到大输出
发布网友
发布时间:2023-08-03 15:16
我来回答
共3个回答
热心网友
时间:2024-11-17 14:12
public void compare(int x, int y, int z){
if(x < y){
if(x < z){
System.out.println(x);
if(y < z){
System.out.println(y);
System.out.println(z);
}else {
System.out.println(z);
System.out.println(y);
}
}else {
System.out.println(z);
System.out.println(x);
System.out.println(y);
}
}else {
if(y > z){
System.out.println(z);
System.out.println(y);
System.out.println(x);
}else {
System.out.println(y);
if(x < z){
System.out.println(x);
System.out.println(z);
}else {
System.out.println(z);
System.out.println(x);
}
}
}
}
热心网友
时间:2024-11-17 14:12
1、
public static void main(String []args)
{
System.out.println("请输入三个整数:");
Scanner input=new Scanner(System.in);
int []num =new int[3];
num[0]=input.nextInt();
num[1]=input.nextInt();
num[2]=input.nextInt();
Arrays.sort(num);
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}
}
2、运行效果
热心网友
时间:2024-11-17 14:13
不对啊,我显示有两处错误