題目:寫一個函數,求一個字符串的長度,在 main 函數中輸入字符串,並輸出其長度。
import java.util.Scanner;
public class WangDao {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Input the string: ");
String str = scan.nextLine();
char[] ch = str.toCharArray();
int n = ch.length;
System.out.println("The length of the string is " + n);
}
}