题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String inputStr = sc.nextLine();
int length = 0;
if (inputStr==null || inputStr.equals("")) {
length = 0;
} else {
String[] arr = inputStr.split(" ");
int arrLength = arr.length;
if (arrLength >=1){
String lastStr = arr[arrLength-1];
length = lastStr.length();
} else {
length = 0;
}
}
System.out.println(length);
}
}
