我需要一个wordcount的程序

编程入门 行业动态 更新时间:2024-10-28 11:18:54
本文介绍了我需要一个wordcount的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要弄清楚如何制作一个程序来计算用户输入的句子中的单词。用户还输入每个单词必须的长度。因此,如果用户输入5个字母的单词,则该句子包含4个字母的单词;这个词不计算在内。

I need to figure out how to make a program that counts the words in a sentence that the user inputs. The user also inputs the length that each word must be. So, if the user inputs 5 letter words, and the sentence includes a 4 letter word; that word won't be counted.

这就是我所拥有的......

This is all I have...

public class wordcount { public static void main(String[] args) { int length = IO.readInt(); String sentence = IO.readString(); int full = sentence.length(); int wordcount = 0; for(int i = 0; i < length; i++){ } System.out.print(wordcount); } }

推荐答案

return sentence.split("\\s+").length;

更多推荐

我需要一个wordcount的程序

本文发布于:2023-11-07 22:12:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   wordcount

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!