我是新來的java和我堅持非常簡單的代碼。我已經添加了while
條件,但日食仍然要求它。我是一個新的Java。我已經添加了while條件,但日食仍然要求它
錯誤:
Syntax error, insert
while (Expression);
to complete BlockStatements
代碼:
package assignment517;
import java.util.Scanner;
public class Products {
public static void main(String[] args) {
// TODO Auto-generated method stub
do{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of product");
int numberOfProduct=input.nextInt();
System.out.print("Enter the products sold");
int productsSold=input.nextInt();
double pprice = 1.0;
switch(numberOfProduct){
case 1: {
System.out.print("Price of total products sold");
System.out.print (pprice= 2.98*productsSold);
break;
}
case 2: {
System.out.print("Price of total products sold");
System.out.print(pprice= 4.50*productsSold);
break;
}
case 3: {
System.out.print("Price of total products sold");
System.out.print(pprice= 9.98*productsSold);
break;
}
case 4: {
System.out.print("Price of total products sold");
System.out.print(pprice= 4.49*productsSold);
break;
}
case 5:{
System.out.print("Price of total products sold");
System.out.print(pprice= 6.87*productsSold);
break;
}
default:{
System.out.print("invalid value");
}
}while(numberOfProduct !=6);
}
}
你可以粘貼它給你的完整的錯誤信息嗎? – iamnotmaynard 2014-09-18 18:29:21
刪除您的病例陳述中的「{}」。 – csmckelvey 2014-09-18 18:30:00
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html – iamnotmaynard 2014-09-18 18:30:04