Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a code defining an integer array of size = 5 and a string array to store \

ID: 3581523 • Letter: W

Question

Write a code defining an integer array of size = 5 and a string array to store "word", and prints all the elements of these two arrays in two separate lines. Write a function ArrayModify that modifies the 4th element of the integer array by making it 3 times bigger, and in main code print the original and modified elements Write a function named ElementDouble that doubles the value of the modified 3rd element, and prints the value double. In main, print the 3rd element before and after calling function Element Double.

Explanation / Answer

ArrayValues.java


import java.util.Arrays;

public class ArrayValues {


   public static void main(String[] args) {
  int a[] ={1,2,3,4,5};
       String s[] = {"word"};
       System.out.println(Arrays.toString(a));
       System.out.println(Arrays.toString(s));
       ArrayModify(a);
       System.out.println(Arrays.toString(a));
       ElementDouble(a);
       System.out.println(Arrays.toString(a));
   }
   public static void ArrayModify(int a[]){
       a[3] = 3 * a[3];
   }
   public static void ElementDouble(int a[]){
       a[2] = 2 * a[2];
   }
}

Output:

[1, 2, 3, 4, 5]
[word]
[1, 2, 3, 12, 5]
[1, 2, 6, 12, 5]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote