需求说明:循环输入商品编号,显示对应的商品价格
输入“n”结束循环
package 测试;
import java.util.Scanner;
import java.util.Stack;
/**
* @author xcdq.SGS
* @date 2021/4/17 9:49
*/
public class demo2 {
public static void main(String[] args) {
String answer = "y";
while (answer.equals("y")) {
System.out.println("管理系统>购物结算");
System.out.println("*************************");
System.out.println("请选择购买的商品编号:\n" + "1,T恤 \t2.网球鞋 \t3.网球拍");
System.out.println("*************************");
Scanner input = new Scanner(System.in);
System.out.println("请输入商品编号:");
int bianhao = input.nextInt();
switch (bianhao) {
case 1:
System.out.println("T恤 \t ¥240.0");
break;
case 2:
System.out.println("网球鞋 \t ¥300.0");
break;
case 3:
System.out.println("网球拍 \t ¥100.0");
break;
default:
System.out.println("输入错误!");
break;
}
System.out.println("是否继续?(y/n)");
Scanner in = new Scanner(System.in);
answer = in.next();
}
System.out.println("程序结束!");
}
}