题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
import java.io.InputStream; import java.util.Scanner; public class Main{ public static void main(String [] args) throws Exception{ Scanner scanner=new Scanner(System.in); String str1=scanner.nextLine(); String str2=str1.substring(str1.lastIndexOf(" ")+1); System.out.println(str2.length()); } }