Java经典编程题50道之三十九

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

public class Example39 {
    public static void main(String[] args) {
        length("Hello World!");
    }

    public static void length(String s) {
        int n = s.length();
        System.out.println("输入的字符串为:" + s + ",其长度为:" + n);
    }
}

posted @ 2017-06-08 14:17  本宫在,尔等都是妃  Views(119)  Comments(0Edit  收藏  举报