38 【程序 38 求字符串长度】
题目:写一个函数,求一个字符串的长度,在 main 函数中输入字符串,并输出其长度。
package cskaoyan; public class cskaoyan38 { public static void main(String[] args) { // TODO Auto-generated method stub java.util.Scanner in = new java.util.Scanner(System.in); System.out.println("please input a string:"); String str = in.nextLine(); char[] arr = str.toCharArray(); System.out.println("the string has " + arr.length + " characters."); in.close(); } }