title: Comparing two arrays in java with for loop
body: <p>I am having difficulties with this program. I have to compare the two arrays by reading the arrays from the console and after the user enters them, print a statement for whether or not they are true. I am not sure if I can use the compare function, but I have to do it with a for loop.</p>
  
  <p>Here is what I have tried:</p>
  
  <pre><code>import java.util.Scanner;
  
  @SuppressWarnings("unused")
  public class TwoArrays {
      @SuppressWarnings("unused")
      public static void main(String[] args) {
  
          Scanner input1 = new Scanner(System.in);
          System.out.println("enter the first array");
          String firstArrayAsString = input1.nextLine();
  
          System.out.println("enter the second array");
          String secondArrayAsString = input1.nextLine(); 
  
          if (firstArrayAsString. length() != secondArrayAsString.length()){
              System.out.println("false.arrays are not equal");       
          } else {
              int arrayLen = firstArrayAsString.length();
              char[] firstArray = firstArrayAsString.toCharArray();
              char[] secondArray = secondArrayAsString.toCharArray();
  
              int i = 0;
              while (i &lt; arrayLen &amp;&amp; firstArray[i] == secondArray[i]); {
                  i++;
              }
  
              if (i == arrayLen) {
                  System.out.println("true.they are equal");
              } else {
                  System.out.println("False.they are not equal");
              }
          }
          input1.close();
      }
  }
  </code></pre>