如何将字符串与多个字符串数组进行比较

时间:2015-09-13 01:40:20

标签: java arrays string logic

我正在尝试编写一个程序,其中用户输入他们的购物清单然后根据项目的类型,程序将为您提供购买物品的良好订单(即将肉类放在一起和蔬菜一起) 这是我当前的问题,我无法获得用户输入来比较我对商店项目的多个字符串类型数组。

String[] VegiFruit = {"Apples", "Lettuce", "Broccoli"};
String[] Meats = {"Ground beef", "Hambuger"};

Scanner USER_IN = new Scanner(System.in);
Methods Use = new Methods(); //This is another class I have, it just makes printing empty lines and lines  of **** look nicer

Use.border();
System.out.println("Enter Item name then follow instructions.");
Use.space();

System.out.print("Item 1: ");
String InptOne = USER_IN.nextLine();

}
for (int i = 0; i < VegiFruit.length; i++)
{
    if(Arrays.asList(VegiFruit).contains(InptOne))
    {
        System.out.println("Item is a VEGI");
    }
}
for(int p = 0; p < Meats.length; p++)
{
    if(Arrays.asList(Meats).contains(InptOne))
    {
       System.out.println("Item is a MEAT");
    }
}

0 个答案:

没有答案