package buy;
import java.util.Scanner;
public class buy {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("****************************");
System.out.println("编号\t商品名称\t商品价格");
System.out.println("1\t牙刷\t8.8");
System.out.println("2\t毛巾\t10.0");
System.out.println("3\t水杯\t18.8");
System.out.println("4\t苹果\t12.5");
System.out.println("5\t香蕉\t15.5");
System.out.println("****************************");
int shopId = 0;
int shopNumber = 0;
double shopMenoy = 0.0;
String choice = "Y";
Scanner sc = new Scanner(System.in);
while(true)
{
System.out.println("请输入购买商品编号:");
shopId = sc.nextInt();
System.out.println("请输入购买商品数量:");
shopNumber = sc.nextInt();
switch(shopId)
{
case 1:
shopMenoy += shopNumber*8.8;
break;
case 2:
shopMenoy += shopNumber*10.0;
break;
case 3:
shopMenoy += shopNumber*18.8;
break;
case 4:
shopMenoy += shopNumber*12.5;
break;
case 5:
shopMenoy += shopNumber*15.5;
break;
default:
System.out.println("您输入的编号错误!");
break;
}
System.out.println("是否继续购物(N/Y)?");
choice = sc.next();
if(choice.equals("N")|choice.equals("n"))
break;
else
System.out.println("您购买" + shopId + "号商品" + shopNumber + "件" + "共" + shopMenoy + "元");
}
System.out.println("您购买" + shopId + "号商品" + shopNumber + "件" + "共" + shopMenoy + "元");
}
}
为啥只有商品1类,6件会初问题,其他的没问题