Question: This exercise includes a starter.java file. Use the starter file to write your program but make sure you do make changes ONLY in the

This exercise includes a starter.java file. Use the starter file to write your program but make sure you do make changes ONLY in the area of the starter file where it is allowed, between the following comments: //#######your code starts here. //#######your code ends here if you modify the starter file anywhere else the Test will fail. Write a class called Increment Each Element containing a main method. Use the starter provided to create a reference to firstArray called reference and a copy of firstArray called copy. The starter declares the names firstArray, reference, and copy. just need to assign the appropriate array to each name. Then the starter calls the method incr which increments each element of each array by 1. Then the three arrays are printed. You cannot use the method Arrays.copyOf. examples % java IncrementEachElement 1 2 3 4 5 firstArray: [2, 3, 4, 5, 6] secondArray: [2, 3, 4, 5, 6] % java IncrementEach Element 0 firstArray: [1] secondArray: [1] % java IncrementEach Element 3579 firstArray: [4, 6, 8, 10] secondArray: [4, 6, 8, 10] //my version import java.util.*; public class IncrementEachElement { } public static int [] readArray(){ String ss = input.nextLine(); String [] aa = ss.split("[, ]"); int[] int_array = new int [aa. length]; if (aa [0]. length() == 0){ } //System.out.println("" + Arrays.toString(int_array)); int_array = new int [0]; return int_array; } // int ii = 0; for (String str: aa) { } int_array[ii++] = Integer.parseInt(str); } public static void incr(int [] aa) { } return int_array; for (int x = 0; x < aa.length; x++){ aa[x] = aa[x] + 1; } static Scanner input = new Scanner(System.in); public static void main (String[] args) { int [] firstArray; int [] reference; int[] copy; firstArray = readArray(); //#######your code starts here. //create a reference (or alias) to firstArray called "reference" //create a copy of firstArray called "copy" //#######your code ends here //the method incr adds 1 to each element of the array incr(firstArray); incr(reference); incr(copy); System.out.println("firstArray: " + Arrays.toString(firstArray)); System.out.println("reference: + Arrays.toString(reference)); System.out.println("copy: " + Arrays.toString(copy));
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
