字符串长度计算
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String words = input.nextLine();
int index = words.lastIndexOf(" ");
if (index < 0) {// 找不到空格下标,表示只输入是一个单词
System.out.println(words.length());
return;
}
String word = words.substring(index + 1);//截取最后一个空格后面的部分字符串
System.out.println(word.length());
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String words = input.nextLine();
int index = words.lastIndexOf(" ");
if (index < 0) {// 找不到空格下标,表示只输入是一个单词
System.out.println(words.length());
return;
}
String word = words.substring(index + 1);//截取最后一个空格后面的部分字符串
System.out.println(word.length());
}
}
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
05-06 17:14
河南科技大学 Java 点赞 评论 收藏
分享
06-23 16:15
西南科技大学 Web前端 点赞 评论 收藏
分享