public static void main(String [] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
double price = 0,allPrice=0;
boolean flag=true;
while(flag){
System.out.println("请输入商品编号,按回车结束,输入0退出");
String a=br.readLine();
int num;
switch (a) {// >jdk1.7才支持switch(string)
case "0":
flag=false;
continue;
case "1":
price=2.98;
break;
case "2":
price=4.50;
break;
case "3":
price=9.98;
break;
case "4":
price=4.49;
break;
case "5":
price=6.87;
break;
default:
System.out.println("没有这商品,重输");
continue;
}
System.out.println("请输入数量");
num=Integer.parseInt(br.readLine());
allPrice+=price*num;
}
System.out.println(allPrice);
} |