title: Can not figure out Javas strings?
body: <p>I am a student at the moment so I am still learning. I picked up VB pretty quick and it was simple Java on the other hand I am pretty confused on. </p>
  
  <p>The Assignment I have been given this time has me confused "Write a method to determine the number of positions that two strings differ by. For Example,"Peace" and "Piece" differ in two positions. The method is declared int compare(String word1, String word2); if the strings are identical, the method returns 0. It returns -1 if the two strings have different lengths." </p>
  
  <p>Additional "Write a main method to test the method. The main method should tell how many, positions the strings differ, or that they are identical, or if they are different lengths, state the lengths. Get the strings from the console.
  So far this is where I am at and I am looking for someone to help break this down in I DUMDUM terms if they can I don't need a solution only help understanding it.</p>
  
  <pre><code>package arraysandstrings;
  import java.util.Scanner;
  
  public class differStrings {
      public static void main (String agrs[]){
          Scanner scanner = new Scanner (System.in);
          System.out.print("Enter a word");
          String word1;
          String word2;
          word1 = scanner.next();
          System.out.print("Enter another word");
          word2 = scanner.next();
          int count = 0;
          int length = word1.length();
  
          for(int x = 0; x &gt;= length; x = x+1) {
              if (word1.charAt(x) == word2.charAt(x)) {
                  count = count + 1;
                  System.out.print (count);
              }
          }
      }
  }
  </code></pre>
  
  <p>Additional Question</p>
  
  <pre><code>   package arraysandstrings;
     import java.util.Scanner;
  
   public class differStrings {
   public static void main (String agrs[]){
   Scanner scanner = new Scanner (System.in);
   System.out.println("Enter a word");
   String word1 = scanner.next();
  
  System.out.println("Enter another word");
  String word2 = scanner.next();
  int count = 0;
  int word1Length = word1.length();
  int word2Length = word2.length();
  
  if (word1Length != word2Length) {
        System.out.println ("Words are a diffrent length");
        System.out.println (word1 + "Has" + word1.length() + " chars");
        System.out.println (word2 + "Has" + word2.length() + " chars");
  }
  
  for(int x = 0; x &lt; word1Length; x = x+1) {
  
         if (word1.charAt(x) != word2.charAt(x)) {
          count = count + 1;
         }}}
  
   System.out.println (count+" different chars");
  </code></pre>
  
  <p>}</p>
  
  <p>After implementing the knowledge Iv gained from your responses I have ran in to a problem with the last line:</p>
  
  <pre><code> System.out.println (count+" different chars");
  </code></pre>
  
  <p>It says Error  expected however it worked before I added the next part of my assignment which was this:</p>
  
  <pre><code>   if (word1Length != word2Length) {
        System.out.println ("Words are a diffrent length");
        System.out.println (word1 + "Has" + word1.length() + " chars");
        System.out.println (word2 + "Has" + word2.length() + " chars");
  }
  </code></pre>