38 写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。

 题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。  

 1    public class _038PrintLength {
 2 
 3     public static void main(String[] args) {
 4         printLength();
 5     }
 6 
 7     private static void printLength() {
 8         Scanner scanner = new Scanner(System.in);
 9         System.out.println("请输入一个字符串 :");
10         String string = scanner.nextLine();
11         System.out.println("字符串的长度是 :" + string.length());
12     }
13 
14 }
原文地址:https://www.cnblogs.com/liuyangfirst/p/6544479.html