私は&をセットを使用して文字列に印刷することを試みています。私を助けてください。Setを使用してPalindromeの単語を印刷する方法
import java.util.*;
public class PalindromeCount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence");
String str = sc.nextLine();
String words[] = str.replaceAll("," , " ").split("");
Set set = new HashSet();
for(String wordL : words)
{
// I am retrieving each word in String and sending it to the sb
StringBuffer sb = new StringBuffer(wordL);
if(sb.reverse().equals(wordL))// here I am checking whether it is palindrome or not if it is palindrome I am adding to set
{
set.add(wordL);
}
}
System.out.println(set);
}
}
[なぜ「誰かが私を助けることはできますか?」ではない、実際の質問?](https://meta.stackoverflow.com/q/284236/3788176) –
あなたが直面している問題は何?あなたはこのコードが[動作しない]と思います(http://importblogkit.com/2015/07/does-not-work/)? – Pshemo
'sb.reverse()。equals(wordL)'は 'StringBuilder'を' String'と比較しており、常にfalseになります。 'sb.reverse()。toString()。equals(wordL)' –