扫描仪中的字符串

时间:2016-03-06 03:11:12

标签: java string object java.util.scanner

我是初学程序员,我正在尝试创建一个涉及扫描仪和对象的随机代码,但我遇到了涉及扫描程序的问题。这是我的代码:

    package jrJava.objectPracticeHome;

import java.util.Scanner;

public class Coordinator {

public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    GroceryStore groceryStore = new GroceryStore();
    System.out.println("Welcome to the Zhenda Grocery Store! We sell pears, apples, and oranges!");
    System.out.println("Type in 'apple', 'orange' or 'pear' to view the number of each fruit. ");

    String fruit = scanner.next();

    if(fruit == "apple"){
        System.out.println(groceryStore.getAppleInv());
    }
    else if(fruit == "orange"){
        System.out.println(groceryStore.getOrangeInv());
    }
    else if(fruit == "pear"){
        System.out.println(groceryStore.getPearInv());
    }



}

}

我确定我正确地调用了这些方法,并且在运行它时没有弹出错误。请帮忙! :P谢谢!

0 个答案:

没有答案