我是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