title: Insert a comma after each item but not the last item
body: <p>I have a program in java that when you enter a sentence and the program tells you how many palindrome words there are and outputs the words. However, when I output the words I can't seem to get a comma after each output. For example if I input "Abba is running to the radar" It outputs that there's 2 palindromes and that the palindromes are "<strong>Abba radar</strong>". I however want it to output the palindromes as "Abba, Radar". No matter how I do it I can either get "Abba Radar" or "Abba, Radar". Any help would be appreciated.</p>
  
  <p>The code</p>
  
  <pre><code>package strings;
  
  import javax.swing.*;
  
  public class Palindrome2 {
  
  public static void main(String[] args) {
      String word = JOptionPane.showInputDialog("Words that are the same forwards and backwards are called palindromes.\nThis program determines if the words are palindromes.\n\nEnter a sentence(do not include a punctuation mark):");
  
      String newWord[] = word.split(" ");
      String palindromeWords = "";
      int count = 0;
  
      for (int i = 0; i &lt; newWord.length; i++) {
          String result = new StringBuffer(newWord[i]).reverse().toString();
          if (newWord[i].toLowerCase().equals(result.toLowerCase())) {
              count++;
              palindromeWords = palindromeWords + " " + newWord[i];
          }
      }
      JOptionPane.showMessageDialog(null, "There are " + count + " palindromes in this sentence");
      if (count != 0) {
          JOptionPane.showMessageDialog(null, "The palindromes are:\n" + palindromeWords);
      } else {
          JOptionPane.showMessageDialog(null, "There isn't any palindromes.");
      }
  }
  }
  </code></pre>