我是java
的新手,需要一些帮助。我写了这个代码,但它跳到结束,不要让我在写东西控制台..无法从键盘读取字符串(Java)
import java.util.Scanner;
public class Exercise21 {
public static void main(String[] args){
Scanner keyboardInput = new Scanner("System.in");
String text = "";
String text2 = "";
System.out.println("Type any text : ");
if(keyboardInput.hasNextLine()) text = keyboardInput.nextLine();
System.out.println("Type the word you want to find : ");
if(keyboardInput.hasNextLine()) text2 = keyboardInput.nextLine();
System.out.println("Your word was found : " + text.indexOf(text2,0));
}
}
“System.in”不应该在引号内 – smoggers
我注意到,tkank你! – Gabriel