Java 不接受诸如whats up之类的话

Java 不接受诸如whats up之类的话,java,Java,我试着让我的程序接受诸如whats up,hows things之类的词,但它并不是所有的连接都是诸如hello,hi之类的词,但不接受任何带有空格的词,如{whats up}有人能解释一下我做错了什么吗?我的代码没有错误,只是我试图让它接受像whats up,How you这样的词 * To change this license header, choose License Headers in Project Properties. * To change this te

我试着让我的程序接受诸如whats up,hows things之类的词,但它并不是所有的连接都是诸如hello,hi之类的词,但不接受任何带有空格的词,如{whats up}有人能解释一下我做错了什么吗?我的代码没有错误,只是我试图让它接受像whats up,How you这样的词

    * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */

    package bot;

    import java.util.*;

    /**
     *
     * @autr kesha
     */
    public class tst {
        public static void main(String[] args){
            Scanner input=new Scanner(System.in);



        HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
        // the ArrayList replaces your HashSet.
        ArrayList<String> list = new ArrayList<String>();   
        ArrayList<String> list1 = new ArrayList<String>();  
        Random r = new Random();

        list.add("Hello");
        list.add("Hi");
        list.add("How's you whats up");
        list.add("Hey");

        list1.add("Yuh mother");

        map.put("hi", list);
        map.put("whats up", list);
        map.put("hello", list);

        map.put("hoe", list1);


        System.out.println("enter Hi");
        String str = input.next().toLowerCase().trim();

        while(map.containsKey(str)){

        if (map.containsKey(str)) {
            ArrayList<String> tmpList = map.get(str); 

            int randomNumber = r.nextInt(tmpList.size()); 

            System.out.println(tmpList.get(randomNumber)); 

 System.out.println("enter Hi");

        str = input.next().toLowerCase().trim();
        }
    }

    }
*要更改此许可证标题,请在项目属性中选择许可证标题。
*要更改此模板文件,请选择工具|模板
*然后在编辑器中打开模板。
*/
一揽子bot;
导入java.util.*;
/**
*
*@autr-kesha
*/
公共级tst{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);
HashMap=newHashMap();
//ArrayList将替换哈希集。
ArrayList=新建ArrayList();
ArrayList list1=新的ArrayList();
随机r=新随机();
添加(“你好”);
列表。添加(“Hi”);
列出。加上(“你好吗?”);
列表。添加(“嘿”);
列表1.添加(“您的母亲”);
地图放置(“hi”,列表);
地图。张贴(“什么事”,列表);
map.put(“你好”,列表);
地图放置(“锄头”,列表1);
System.out.println(“输入Hi”);
String str=input.next().toLowerCase().trim();
while(map.containsKey(str)){
if(地图容器(str)){
ArrayList tmpList=map.get(str);
int randomNumber=r.nextInt(tmpList.size());
System.out.println(tmpList.get(randomNumber));
System.out.println(“输入Hi”);
str=input.next().toLowerCase().trim();
}
}
}
您正在呼叫,它“查找并返回来自此扫描仪的下一个完整令牌”

您希望调用,这需要一整行输入。

我相信。next()将字符串剪切到空白处。 试试这个

String str = input.nextLine().toLowerCase().trim();

你能详细说明一下你的代码出了什么问题吗?有错误吗?
input.next()
只返回下一个单词。因此如果有多个单词,你就倒霉了。试着改用
nextLine()
。你的代码不会运行。