Home java Help Compare Two String Massif Using Standard Comparison Methods

Help Compare Two String Massif Using Standard Comparison Methods

Author

Date

Category

You need to write a method of comparing two string type arrays. Made checks for the length of arrays, on the identity of the length of words in the cells of the array. And now it is necessary to compare words in the same array cells in the same way and here the snag. That’s what I have yet happened to do:

Public Static Void Main (String [] Args) Throws Exception {
  STRING [] F1 = {"RED", "Black", "Blue"};
  STRING [] S2 = {"RED", "BLOCK", "BLUE"};
  System.Out.printLN (CompareStringArries (F1, S2));
}
Public Static Boolean COMPARESTRINGARRAYS (String [] First, String [] Second) Thrown Exception {
  if (first == null || second == null)
    Throw New Exception ("This Object Is Not Exist");
  if (first.length! = Second.Length)
    Throw New Exception ("The Length of Arrays Is Not The Same");
  For (int i = 0; i & lt; first.length; i ++) {
    For (int j = 0; j & lt; second.length; j ++) {
      if (i == j & amp; & amp; first [i] .length ()! = Second [j] .length ()) {
        RETURN FALSE;
      }
    }
  }
  For (int i = 0; i & lt; first.length; i ++) {
    For (int j = 0; j & lt; second.length; j ++) {
      if (i == j) {
        For (int k = 0; k & lt; first [i] .length (); k ++) {
          For (int l = 0; L & lt; Second [j] .length (); l ++) {
            if (k == l & amp; & amp;) {
            }
          }
        }
      }
    }
  }
  RETURN TRUE;
}

In the brain I understand that it is necessary to compare, and how to do it I do not figure it out …
Thank you in advance for the answer and explanation.


Answer 1, Authority 100%

I got this decision:

public static boolean comparestringarrays (String [] First, String [] Second) Throwns Exception {
  if (first == null)
    RETURN SECOND == NULL;
  ELSE if (second == null)
    RETURN FALSE;
  if (first.length! = Second.Length)
    RETURN FALSE;
  int size = first.length;
  For (int indexofstring = 0; indexofstring & lt; size; indexofstring ++)
    IF (GetLength (FIRST, INDEXOFSTING)! = GetLength (Second, Indexofstring))
      RETURN FALSE;
    ELSE.
      For (int indexofsymbol = 0; indexofsymbol & lt; GetLength (first, indexofstring); indexofsymbol ++)
        if (first [indexofstring] .charat (indexofsymbol)! = Second [indexofstring] .charat (indexofsymbol))
          RETURN FALSE;
  RETURN TRUE;
}
Private Static Int Getlength (String [] Array, Int Index) {
  Return Array [index] == NULL? 0: Array [index] .length ();
}

Answer 2

And why not just do so?

// in the future, instead of first.Length you need to insert an array, with the greatest
  // number Item's
  For (int i = 0; i & lt; first.length; I ++) {
  // Since the check on the same number of letters already has, you can this if
  // Simplify
          char [] firstword = first [i] .tocararray ();
          char [] secondword = second [i] .tocararray ();
          For (int i = 0; i & lt; firstword.length (); i ++)
          {
           If (firstword [i]! = SecondWord [i]) {return false; }
          }
   } // if you do not return FALSE, then check is performed successfully.

Not the best solution (wrote on an ambulance hand), but the principle you must understand.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions