我製作了一個程序,用於計算用戶輸入的字符串的長度。我的程序大部分工作正常,但是當我打印「Hello World」時,它給出長度5(而應該是11)。我怎樣才能解決這個問題?計算字符串輸入的長度
import java.util.Scanner;
public class StringLength {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter the string: \n");
String word = in.next();
System.out.println("The length is: " +word.length());
}
}
也許你應該避免回答,因爲這是以前很多問題的重複。 –