Question

In: Computer Science

public int getIndexOfWord(String[] arr, String word){ // if found, return the index of word, otherwise return...

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

}

Solutions

Expert Solution

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;

    }

Related Solutions

class Arrays1{ public int getSumOfValues(int[] arr){ // return the sum of values of array elements int...
class Arrays1{ public int getSumOfValues(int[] arr){ // return the sum of values of array elements int sum = 0; int i; for(i = 0; i < arr.length; i++){ sum += arr[1]; } return sum; } public int getAverageValueInArray(int[] arr){ // return the average value of array elements int value = 0; for(int i = 0; i < arr.length; i++){ double average = value/ arr.length; } return value; } public int getNumberOfEvens(int[] arr){ //return the number of even values found in...
public boolean isPrime(int num){ // return true if the number is prime, false otherwise } public...
public boolean isPrime(int num){ // return true if the number is prime, false otherwise } public boolean isOdd(int num){ // return true if the number is odd, false otherwise } public String reverseMyString(String input){ // using a loop, reverse a string // i.e. input = "hello", reversed answer: "olleh" // i.e. input = "bye", reversed answer: "eyb" } public int pow(int base, int power){ // using for loop, calculate base raised to power // i.e. base = 2, power =...
class ArrayReverse1{ public static void reverse(int[] a, int index) { if (index >0) { index= index...
class ArrayReverse1{ public static void reverse(int[] a, int index) { if (index >0) { index= index - 1; // Decrementing the index System.out.printf("%d%n", a[index]); reverse(a, index); // Recursive call } return; } public static void main (String args[]) { int [] array = { 1, 2, 3, 4, 5 }; int n=array.length; reverse(array,n); // function call } } Write a generic version of the corrected recursive reverse method that could be used to print any of the following arrays (or...
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];...
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];        arr[i] = arr[j];        arr[j] = temp; } void function(int arr[], int length) {        for (int i = 0; i<length / 2; i++)               swap(arr, i, (length / 2 + i) % length); } If the input to the function was int arr[] = { 6, 1, 8, 2, 5, 4, 3, 7 }; function(arr,8); What values would be stored in the array after calling the...
public int static mirroringIt(String str){ return n; } implement this function so its takes ONE string...
public int static mirroringIt(String str){ return n; } implement this function so its takes ONE string and remove the characters so it becomes a mirrored word. example: Input: qswwbi Output: 4 remove q s b i "wow" is a mirror word. output : 0 Input : "if" output : 1 remove either I or f because it's two words. don't use 3rd parties library or java.util.
JAVA please write this method public static void recursiveSelectionSort(int[] arr) { }
JAVA please write this method public static void recursiveSelectionSort(int[] arr) { }
JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
Write a method public static void minMax(int[] arr) that takes an array of unique ints of...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of length at least two as an argument, and swaps the smallest value of the array into the 0th position and swaps the largest value of the array into the last position. For example, if int[] a = {4, 3, 2, 6, 1, 5}, the method call minMax(a) should modify the array so that it is {1, 3, 2, 5, 4, 6}. The method should...
class ArrayStringStack { String stack[]; int top; public arrayStringStack(int size) { stack = new String[size]; top...
class ArrayStringStack { String stack[]; int top; public arrayStringStack(int size) { stack = new String[size]; top = -1; } //Assume that your answers to 3.1-3.3 will be inserted here, ex: // full() would be here //empty() would be here... //push() //pop() //displayStack() } 1. Write two boolean methods, full( ) and empty( ). 2. Write two methods, push( ) and pop( ). Note: parameters may be expected for push and/or pop. 3. Write the method displayStack( ) that prints the...
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT