【王道JAVA】【程序 38 求字符串长度】

题目:写一个函数,求一个字符串的长度,在 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);
	}
}

猜你喜欢

转载自blog.csdn.net/YelloJesse/article/details/89431318