我不确定为什么此代码不起作用。我想从while循环开始,如果满足条件,则继续进行三种可能的执行之一。
Scanner kb = new Scanner(System.in);
System.out.println("Please enter a valid product code to find out the percentage markup - DRY or FRO or HRW");
String code = kb.nextLine();
do { System.out.println("Please enter a valid product code to find out the percentage markup - DRY or FRO or HRW");
code = kb.nextLine(); }
while(code.charAt(code.length()-1)=='Y' || code.charAt(code.length()-1)=='O' || code.charAt(code.length()-1)=='W');
switch (code.charAt(code.length()-1)) {
case 'Y':
{
System.out.println("The cost of Dairy is €2 and the markup is 20% please enter the number of dairy products");
int markup = kb.nextInt();
System.out.println("The markup for the product that you have selected is : €" +markup*0.2);
break;
}
case 'O':
{
System.out.println("The cost of Frozen is €1 and the markup is 50% please enter the number of frozen products");
int markup = kb.nextInt();
System.out.println("The markup for the product that you have selected is : €" +markup*0.5);
break;
}
case 'W':
{
System.out.println("The cost of Hardware is €5 and the markup is 25% please enter the number of harware products");
int markup = kb.nextInt();
System.out.println("The markup for the product that you have selected is : €" +markup*0.25);
break;
}
default:
break;
}
}
}