从键盘上输入三个整数,分别赋给整型变量a,b,c. 然后将输入的整数按照从小到大的顺序放在a,b,c中, 并输出三个变量的值。

public class Test_16 {

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);
}
}

你可能感兴趣的:(从键盘输入三个整数,a,b,c,从小到大存放,Java基础)