题目:
描述 | |
---|---|
知识点 | 字符串,循环 |
运行时间限制 | 0M |
内存限制 | 0 |
输入 | 一行字符串,长度小于128。 |
输出 | 整数N,最后一个单词的长度。 |
样例输入 | hello world |
样例输出 | 5 |
The java.util.Scanner.hasNext():This method Returns true if this scanner has another token in its input. This method may block while waiting for input to scan. The scanner does not advance past any input
StringcharAt() Method:This method returns the character located at the String's specified index. The indexes start from zero.
java.util.Scanner.Next():This method returns a String object which is a complete token of the Scanner object.
Example:
public class Test { public static void main(String args[]) { String s = "Strings are immutable"; char result = s.charAt(8); System.out.PRintln(result); }}Result:a
新闻热点
疑难解答