【发布时间】:2020-05-02 08:46:52
【问题描述】:
我想编写一个程序,要求用户输入订票的客户数量,读取输入的数字,执行循环询问每个客户的年龄,并确定每个客户的单价。 到目前为止,我的代码只有 if else 语句:
if (customerP <4){
System.out.println("The unit Price of customer 1 is: 0");
}else {
if(customerP <13) {
System.out.println("The unit price of customer 1 is: 5");
}else {
if(customerP <19) {
System.out.println("The unit price of customer 1 is: 8");
}else {
System.out.println("The unit price of customer 1 is: 10");
}
}
}
如何添加一个 while 循环来询问每个客户的年龄?
【问题讨论】:
-
在一个命令中查看
else if,避免像这里一样重叠
标签: java while-loop do-while