我试图将它转换为char,但我仍然遇到一个问题,它无法正常构建,新手在这里。但任何帮助都可以做到
import java.util.Scanner;
public class PizzaChoice {
public static void main(String[] args){
//char sizes;
Scanner input = new Scanner(System.in);
final int NUMBER_OF_CHOICES = 4;
char[] pizzaSize = {'S', 'M', 'L', 'X'};
double[] prices = {6.99, 8.99, 12.50, 15.00};
char sizeChosen;
double pizzaPrice = 0.0;
boolean validChoice = false;
Scanner inputDevice = new Scanner(System.in);
System.out.print("Enter pizza size- S, M, L, or X: ");
sizeChosen = inputDevice.nextLine().charAt(0);
for(int s = 0; s < NUMBER_OF_CHOICES; ++s)
{
if(sizeChosen.equals(pizzaSize[s]))
{
validChoice = true;
pizzaPrice = prices[s];
}
}
if(validChoice)
System.out.println("The price for chosen size " +
sizeChosen + " is $" + pizzaPrice);
else
System.out.println("Sorry - Invalid Choice Entered");
}
}
答案 0 :(得分:0)
替换char为pizzaSize和sizeChosen by Character,它将起作用。见"Char cannot be dereferenced" error