【程序38】
題目:寫一個函數(shù),求一個字符串的長度,在main函數(shù)中輸入字符串,并輸出其長度。
package com.share.test31_40;
import java.util.Scanner;
public class Test38 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("請輸入您要輸入的字符串:");
String str=sc.nextLine();
test(str);
}
public static void test(String str){
System.out.println(str.length());
}
}