title: Counting and Outputting like characters between two strings
body: <p>I would like to compare two user-defined strings and output the count of the number of characters shared between the two strings, without resorting to using arrays. I then need to output each of those characters. I understand the user-input part using a Scanner, but afterwards I am clueless. </p>
  
  <p>For example, "hamper" as string1, and "happened" as string2 would return:</p>
  
  <p>number of shared characters = 5</p>
  
  <p>shared characters >> "h", "a", "p", "p", "e", "e"</p>
  
  <p>Here is what i have so far.  It prints each character on a separate line though.  Is there a way without arrays to list them all on one line like above?:</p>
  
  <pre><code>    public class CountMatches {
  
    public static void main(String[] args)
    {
      //Declare both Strings.
      String word1;
      String word2;
      int count = 0;
  
  
      //Call for User Input.
      Scanner inputDevice = new Scanner(System.in);
      System.out.print("Input String 1 &gt;&gt; ");
      word1 = inputDevice.next();
      System.out.print("Input String 2 &gt;&gt; ");
      word2 = inputDevice.next();
      inputDevice.close();
  
      //Determine lengths and set label accordingly.
      String BigWord;
      String SmallWord;
  
      if (word1.length() &gt; word2.length())
      {
          BigWord = word1;
          SmallWord = word2;
      }
      else
      {
          BigWord = word2;
          SmallWord = word1;
      }
  
      //Count and Display the like characters.
      for (int i = 0; i &lt; SmallWord.length(); i++)
      {
          if (BigWord.contains(String.valueOf(SmallWord.charAt(i))))
          {
              System.out.println("both words contain the letter " + SmallWord.charAt(i));
              count++;
          }
      }
  
      //Display the count of like characters.     
      System.out.print("Number of like characters &gt;&gt; " + count);
    }
  
      }
  </code></pre>