如何计算java中相同单词的数量(PALINDROME) [英] how to count the number of words of the same(PALINDROME) in java

查看:90
本文介绍了如何计算java中相同单词的数量(PALINDROME)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java新手.我想编写代码以使用Java计算段落中回文词的数量.
假设是:用户可以输入一个包含尽可能多的句子的段落.每个单词之间用空格隔开,每个句子之间用句点隔开.单词之前或之后的标点符号将被忽略,而单词内部的标点符号将被计数.
样本输入:Otto goes to school. Otto sees a lot of animals at the pets store.
样本输出:Otto = 2 a = 1 Sees = 1

I'm a newbie Java Developer. I want to write code to count the number of palindrome words in the paragraph using Java.
The assumptions are : User can enter a paragraph containing as many sentences as possible. Each word is separated by a whitespace, and each sentence is separated by a period and The punctuation right before or after the word will be ignored, while the punctuation inside the word will be counted.
Sample Input : Otto goes to school. Otto sees a lot of animals at the pets store.
Sample output : Otto = 2 a = 1 Sees = 1

推荐答案

将文件读入程序,在每个空格处拆分条目,然后将其输入到arraylist中.然后,将您的回文算法应用于数组列表中的每个值,并跟踪作为回文的单词及其出现(例如2D数组或具有同时包含两个值的对象的数组列表).

Read the file into your program, split the entries at every space and enter those into an arraylist. Afterwards, apply your palindrome algorithm onto each value in your arraylist and keep track of the words that were a palindrome and their occurences (for example a 2D array, or an arraylist with an object that holds both values).

按照这些步骤进行操作后,您应该已经准备就绪了.一旦您展示了自己的尝试,就可能会提供更具体的帮助.

When you've followed these steps, you should pretty much be there. More specific help will probably be given once you've shown attempts of your own.

这篇关于如何计算java中相同单词的数量(PALINDROME)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆