Question

Write a complete Java program called MethodTest according to the following guidelines. The main method hard-codes...

Write a complete Java program called MethodTest according to the following guidelines. The main method hard-codes three integer values into the first three positions of an array of integers calls a method you write called doubleEachValue that takes an array of integers (the one whose values you hard-coded in main) as its only argument and returns an ArrayList of integers, with each value in returned ArrayList equal to double the correspondingly indexed value in the array that is passed in as the argument to this method calls a method you write called printResults that takes an ArrayList of integers as its only argument and prints on a separate lines the first, second, and third values of the ArrayList that is passed in as the argument to this method

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import java.util.ArrayList;

class Main {

ArrayList<Integer> MethodTest(int[] arr) {

ArrayList<Integer> arrList= new ArrayList<Integer>();

arrList.add(arr[0]*2);

arrList.add(arr[1]*2);

arrList.add(arr[2]*2);

return(arrList);

}

public static void main(String[] args) {

Main m = new Main();

int[] intArr = new int[]{ 1,2,3};

ArrayList<Integer> al= m.MethodTest(intArr);

System.out.println("Elements of ArrayList: "+al);

}

}

java version "1.8.0_31"

Java(TM) SE Runtime Environment (build 1.8.0_31-b13)

Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

Elements of ArrayList: [2, 4, 6]


Add a comment
Know the answer?
Add Answer to:
Write a complete Java program called MethodTest according to the following guidelines. The main method hard-codes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT