控制台没有对用户输入作出响应。我做错了什么?

huangapple 未分类评论48阅读模式
英文:

The console isn't giving a response to user input. What am I doing wrong?

问题

public static void main(String[] args) throws Exception {
    System.out.println("欢迎来到Zayann的比萨店");
    Scanner myPizza = new Scanner(System.in);
    System.out.println("您想要什么比萨? 1)芝士 2)鸡肉 3)牛肉 4)素食 - 请输入编号");
    String[] pizzaSize = {"6 英寸", "9 英寸", "12 英寸", "15 英寸", "20 英寸"};
    String[] pizza = {"芝士", "鸡肉", "牛肉", "素食"};
    String pizzaOrder = myPizza.nextLine();
    if (pizzaOrder.equals("1")) {
        System.out.println("您选择了芝士比萨");
        System.out.println("您想要什么尺寸? 6 英寸,9 英寸,12 英寸,15 英寸,20 英寸 - 请输入尺寸");
    }
}
英文:

I am making a pizza program that asks for the the user's choice of pizza, the size, the toppings and if they want delivery or not. However, I am facing a problem where I input something into the console as input but I don't receive any response. I have included the code.

My Code:

    public static void main(String[] args) throws Exception {
        System.out.println("Welcome to Zayann's Pizza");
        Scanner myPizza = new Scanner(System.in);
        System.out.println("What pizza would you like? 1) cheese 2) chicken 3) beef 4) veg-- Please enter number");
        String[] pizzaSize = {"6 inch", "9 inch", "12 inch", "15 inch", "20 inch"};
        String[] pizza = {"cheese","chicken","beef","veg"};
        String pizzaOrder = myPizza.nextLine();
        if (myPizza.equals(pizza[0])) {
            System.out.println("You have selected cheese");
            System.out.println("What size would you like? 6 inch, 9 inch, 12 inch, 15 inch,20 inch-- Please enter size");
        }
    }

答案1

得分: 0

你正在尝试将一个Scanner(myPizza)与一个字符串(pizza[0])进行比较。

正如 @azro 所说,请粘贴您的代码,而不是上传您的图片。

英文:

You are trying to compare a Scanner (myPizza) with a String (pizza[0]).

And how @azro say, please paste your code, not upload your image.

答案2

得分: 0

你不应该将Scanner对象与String进行比较,尝试使用以下代码:

    public static void main(String[] args) throws Exception {
        System.out.println("欢迎光临Zayann's披萨");
        Scanner myPizza = new Scanner(System.in);
        System.out.println("您想要什么披萨? 1) 芝士披萨 2) 鸡肉披萨 3) 牛肉披萨 4) 素食披萨-- 请输入数字");
        String[] pizzaSize = {"6英寸", "9英寸", "12英寸", "15英寸", "20英寸"};
        String[] pizza = {"芝士披萨","鸡肉披萨","牛肉披萨","素食披萨"};
        String pizzaOrder = myPizza.nextLine();
        if (pizzaOrder.equals(pizza[0])) {
            System.out.println("您选择了芝士披萨");
            System.out.println("您想要什么尺寸? 6英寸、9英寸、12英寸、15英寸、20英寸-- 请输入尺寸");
            String pizzaEnterSize = myPizza.nextLine();
            if (pizzaEnterSize.equals(pizzaSize[0])) {
                System.out.println("您选择了6英寸尺寸");
            }
        }
    }
英文:

You should not to compare a Scanner object with String,try the follow code:

    public static void main(String[] args) throws Exception {
        System.out.println("Welcome to Zayann's Pizza");
        Scanner myPizza = new Scanner(System.in);
        System.out.println("What pizza would you like? 1) cheese 2) chicken 3) beef 4) veg-- Please enter number");
        String[] pizzaSize = {"6 inch", "9 inch", "12 inch", "15 inch", "20 inch"};
        String[] pizza = {"cheese","chicken","beef","veg"};
        String pizzaOrder = myPizza.nextLine();
        if (pizzaOrder.equals(pizza[0])) {
            System.out.println("You have selected cheese");
            System.out.println("What size would you like? 6 inch, 9 inch, 12 inch, 15 inch,20 inch-- Please enter size");
            String pizzaEnterSize = myPizza.nextLine();
            if (pizzaEnterSize.equals(pizzaSize[0])) {
                System.out.println("You chose 6 inch size");
            }
        }
    }

huangapple
  • 本文由 发表于 2020年5月5日 17:49:12
  • 转载请务必保留本文链接:https://java.coder-hub.com/61610255.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定