关于#java#的问题:用户输入任意一个字符串,显示它的长度和第一个字符
问题描述:
编写一个程序,用户输入任意一个字符串,显示它的长度和第一个字符
答
public class DemoApplication {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("输入任意字符:");
String str = scanner.next();
System.out.printf("字符串长度:%s,第一个字符:%s\n", str == null ? 0 : str.length(), str != null && str.length() > 1 ? str.substring(0, 1) : "");
}
}
答
在输入框绑定个失焦事件 输入字符串失去焦点时获取文本框值获取其长度并截取第一位