In: Computer Science
public int getIndexOfWord(String[] arr, String word){
// if found, return the index of word, otherwise return -1
}
public boolean areArrays(int[] arr1, int[] arr2){
// 1. initial check: both arrays need to have the same length,
return false if not the same
// 2. return true if both given arrats are equals(same values in
the same indices), false otherwise
}
public boolean areArraysEqual(String[] arr1, String[] arr2){
// 1. initial check: both arrays need to have the same length,
return false if not the same
// 2. return true if both given arrays are equals(same values in
the same indices), false otherwise
}
public int getIndexOfWord(String[] arr, String word) {
for (int i = 0; i < arr.length; i++) {
if (arr[i].equals(word))
return i;
}
return -1;
}
public boolean areArrays(int[] arr1, int[] arr2) {
if (arr1.length != arr2.length)
return false;
for (int i = 0; i < arr1.length; i++)
if (arr1[i] != arr2[i])
return false;
// 1. initial check: both arrays need to have the same length, return false if
// not the same
// 2. return true if both given arrats are equals(same values in the same
// indices), false otherwise
return true;
}
public boolean areArraysEqual(String[] arr1, String[] arr2) {
// 1. initial check: both arrays need to have the same length, return false if
// not the same
// 2. return true if both given arrays are equals(same values in the same
// indices), false otherwise
if (arr1.length != arr2.length)
return false;
for (int i = 0; i < arr1.length; i++)
if (!arr1[i].equals( arr2[i]))
return false;
// 1. initial check: both arrays need to have the same length, return false if
// not the same
// 2. return true if both given arrats are equals(same values in the same
// indices), false otherwise
return true;
}