我是 Java 新手,想交换两个输入到程序中然后保存为字符串的单词。我包含了一个 if 语句,以确保输入了我要切换的两个单词。
Scanner in = new Scanner(System.in);
System.out.println("Please enter at least one thing you love and one thing you hate using the words hate and love: ");
String loveHate = in.nextLine();
if (loveHate.indexOf( "love" ) == -1 || loveHate.indexOf( "hate" ) == -1 ){
System.out.println("Please include the words love and hate.");
return;
}
我想取用户输入的句子并切换爱和恨这两个词,然后用切换的词重新打印一个新字符串。