Which of the following defines a method doubleEach that retu

Which of the following defines a method doubleEach that returns an array where each element is double the corresponding element in an input array? public double[] doubleEach(double[] input) {double[] temp = new double[input.length]; for (int i = 0; i

Solution

Answer is A

public double[] dobleEach(double [] input)
   {
      
       double[] temp= new double[input.length];
           for(int i=0;i<input.length;i++)
                   {
               temp[i]=input[i] * 2.0;
                   }
           return temp;
   }

---------------------

for more info execute following code

package chegg;

public class MethodCall {
  
   public double[] dobleEach(double [] input)
   {
      
       double[] temp= new double[input.length];
           for(int i=0;i<input.length;i++)
                   {
               temp[i]=input[i] * 2.0;
                   }
           return temp;
   }
  
   public static void main(String[] args) {
       double a[]={2.0,3.0,4.0,6.0};
      
       MethodCall m=new MethodCall();
       int i;
       for(i=0;i<4;i++)
       System.out.println(a[i]);
      
       a=m.dobleEach(a);
       for(i=0;i<4;i++)
           System.out.println(a[i]);  

   }

}

output :

2.0
3.0
4.0
6.0
4.0
6.0
8.0
12.0

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.

 Which of the following defines a method doubleEach that returns an array where each element is double the corresponding element in an input array? public doubl
 Which of the following defines a method doubleEach that returns an array where each element is double the corresponding element in an input array? public doubl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site