描述 | |
---|---|
知识点 | 字符串,循环 |
运行时间限制 | 0M |
内存限制 | 0 |
输入 | 一行字符串,长度小于128。 |
输出 | 整数N,最后一个单词的长度。 |
样例输入 | hello world |
样例输出 | 5 |
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String input = sc.nextLine().trim();
sc.close();
System.out.println(length(input));
}
private static int length(String input){
String[] splitStr = input.split(" ");
int length = splitStr[splitStr.length-1].length();
return length;
}
}