JAVA basic programming exercises program [38] 38 seeking string length

 

[38] string length requirements program 38

Title: Write a function, find a string length, the main function in the input string, and outputs its length.

 

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();
	}
}

 

Guess you like

Origin www.cnblogs.com/denggelin/p/11456695.html
38