Answer to Question #289833 in Java | JSP | JSF for jeffy

Question #289833
READ THE COMMENTS AND THE ASSIGNMENT DOCUMENT. WRITE CODE AS PER THE COMMENTS
class QI1 {
	
	// method that prints an int array
	public static void printIntArray(int[] array) {
		// TODO

	}//printArray


	

	// method that inserts a new key at the index 0 of an array
	public static void insertKey(int[] array, int key) {
		// TODO

	}//insertValue

	// method that removes and returns a key from the index 0 of an array
	public static int removeKey(int[] array) {
		// TODO

	}//insertValue

	// method that copies values from one array to another array
	// returns the new array after copying
	public static String[] copyArray(String[] array) {
		// TODO

	}//insertValue

	// method that checks the values in both argument arrays
	// returns true if all values are equal
	public static boolean arraysEqual(String[] array1, String[] array2) {
		// TODO

	}//arraysEqual

	

	public static void main(String[] args) {
		// TODO


	}//main


}//class




1
Expert's answer
2022-01-22T16:40:29-0500
class QI1 {

    // method that prints an int array
    public static void printIntArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }//printArray


    // method that inserts a new key at the index 0 of an array
    public static void insertKey(int[] array, int key) {
        array[0] = key;
    }//insertValue

    // method that removes and returns a key from the index 0 of an array
    public static int removeKey(int[] array) {
        int value = array[0];
        for (int i = 1; i < array.length; i++) {
            array[i - 1] = array[i];
        }
        array[array.length - 1] = 0;
        return value;
    }//insertValue

    // method that copies values from one array to another array
    // returns the new array after copying
    public static String[] copyArray(String[] array) {
        String[] copy = new String[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        return copy;
    }//insertValue

    // method that checks the values in both argument arrays
    // returns true if all values are equal
    public static boolean arraysEqual(String[] array1, String[] array2) {
        if (array1.length != array2.length) {
            return false;
        }
        for (int i = 0; i < array1.length; i++) {
            if (!array1[i].equals(array2[i])) {
                return false;
            }
        }
        return true;
    }//arraysEqual


    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6};
        printIntArray(array);
        insertKey(array, 0);
        printIntArray(array);
        System.out.println(removeKey(array));
        printIntArray(array);
        String[] colors = {"red", "green", "blue"};
        String[] copyColors = copyArray(colors);
        System.out.println(arraysEqual(colors, copyColors));
        System.out.println(arraysEqual(colors, new String[]{"red", "blue", "green"}));


    }//main


}//class

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog