首页 > 代码库 > 输入三个数字,按从大到小的顺序输出
输入三个数字,按从大到小的顺序输出
import java.util.Scanner;
public class 比大小 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
int x,y,z;
System.out.println("请输入x的值:");
x= sc.nextInt();
System.out.println("请输入y的值:");
y= sc.nextInt();
System.out.println("请输入z的值:");
z= sc.nextInt();
if (x>y)
{
if (y>z)
{System.out.println(z+","+y+","+x);} //不要忘记连接符号 “+”
else {if(x>z)
{System.out.println(y+","+z+","+x);}
else
{System.out.println(y+","+x+","+z);}
}
}
else//x<y
{
if (x>z) // z<x<y
{System.out.println(z+","+x+","+y);}
else { // x<z
if(y>z) // x<z<y
{ System.out.println(x+","+z+","+y);}
else // x<y<z
{System.out.println(x+","+y+","+z);}
}
}
}
}
输入三个数字,按从大到小的顺序输出