国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌拉特中旗| 永修县| 阿图什市| 连山| 聂拉木县| 嘉祥县| 封丘县| 新晃| 清水县| 兴和县| 舒兰市| 多伦县| 灵台县| 商丘市| 肃宁县| 二连浩特市| 灵石县| 临洮县| 南康市| 三门县| 墨脱县| 乌拉特前旗| 宜良县| 灯塔市| 凌源市| 通化市| 吴川市| 隆化县| 揭西县| 抚松县| 三门峡市| 西吉县| 太和县| 鲁山县| 大丰市| 承德县| 甘德县| 剑川县| 古交市| 托克托县| 太仆寺旗|