提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
题目:Java单路分支之按序输出三个数。
代码:
import java.util.Scanner;
/**
* 任务:按升序(从小到大)输出三个数
*/
public class ApplicationTest {
/**
* 请在下面的 Begin - End 之间按照注释中给出的提示编写正确的代码
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 声明整型变量 x , y ,z 获取控制台的输入
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
// 声明整型变量 temp ,用于变量值的临时存储
int temp = 0;
/********** Begin **********/
// 使用 if 语句判断 x、y、z 的大小 ,并将三个数中的最小值赋值给 x,最大值赋值给 z。
if (x > y) {
temp = y;
y = x;
x = temp;
}
if (y > z) {
temp = y;
y = z;
z = temp;
}
if (x > y) {
temp = y;
y = x;
x = temp;
}
/********** End **********/
System.out.println("从小到大排列:" + x + " " + y + " " + z);
}
}
结果:
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了Java单路分支之按序输出三个数。