国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

華為OJ——字符串最后一個單詞的長度

2019-11-08 03:09:21
字體:
來源:轉載
供稿:網友

題目:

描述

計算字符串最后一個單詞的長度,單詞以空格隔開。

知識點字符串,循環
運行時間限制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.

返回Scanner的下一個標記,或指定模式的下一個匹配,即返回的只是第一個輸入

java.util.Scanner.NextLine():  This method returns a String which corresponds to the skipped line 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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黑河市| 工布江达县| 竹山县| 扎赉特旗| 大化| 五峰| 孟津县| 许昌市| 克什克腾旗| 武安市| 嵊泗县| 凤台县| 龙州县| 景宁| 肥东县| 南漳县| 柯坪县| 绥滨县| 康定县| 子长县| 文昌市| 赞皇县| 临朐县| 金湖县| 东明县| 大同县| 利川市| 兰溪市| 大埔县| 江陵县| 运城市| 泾阳县| 濮阳县| 项城市| 奉新县| 山东| 军事| 荔波县| 灵丘县| 宁国市| 张家界市|