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

Could someone please help me write this code in java? Method-Array Lab 1. Write

ID: 3817338 • Letter: C

Question

Could someone please help me write this code in java?

Method-Array Lab

1. Write a method called twiceArray. This method takes an array of double type, it then

multiplies each number in the array by 2, stores the new number back in the array and returns the array back to main.

2. Write a method called xArray. This method takes an array of type double, and another variable of type double (I will call this variable x). It then multiplies each number in the array by x, stores the new number back in the array and returns the array back to main.

Explanation / Answer

ArrayLabTest.java

import java.util.Arrays;


public class ArrayLabTest {

  
   public static void main(String[] args) {
   double a[] = {1,2,3,4,5,6,7,8,9,10};
   twiceArray(a);
   System.out.println(Arrays.toString(a));
   double b[] = {1,2,3,4,5,6,7,8,9,10};
   xArray(b,5);
   System.out.println(Arrays.toString(b));
   }
   public static void twiceArray(double a[]) {
       for(int i=0; i<a.length; i++){
           a[i]=a[i]*2;
       }
   }
   public static void xArray(double a[], int x) {
       for(int i=0; i<a.length; i++){
           a[i]=a[i]*x;
       }
   }

}

Output:

[2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0]
[5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0]

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