用户从控制台输入需要查询的商品编号,根据编号显示对应的商品价格。假设商品名称和商品价格:
public class X5 {public static void main(String[] args) {System.out.println("昌大昌购物管理系统>购物结算");System.out.println("*********************************");System.out.println("请请选择购买的商品编号");System.out.println("1.T恤"+"t"+"2.网球鞋"+"t"+"3.网球拍");System.out.println("*******************************");Scanner scanner=new Scanner(System.in);while (true){System.out.println("请输入商品编号");int ageInt();switch (age){case 1:System.out.println("T恤"+"t"+"$299");break;case 2:System.out.println("网球鞋"+"t"+"$599");break;case 3:System.out.println("网球拍"+"t"+"$99");break;default:System.out.println("编号选择错误");}System.out.println("是否继续(y/n)");String next = ();if("n".equals(next)){System.out.println("程序结束");return;}if (!"y".equals(next)){System.out.println("输入符号错误,请从新输入");}}}
}
结果如下:
本文发布于:2024-01-31 03:09:32,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170664177524903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |