Question: You are going to develop a method that takes an ArrayList of strings as a parameter, iterates through that ArrayList and greets every element in

You are going to develop a method that takes an ArrayList of strings as a parameter, iterates through that ArrayList and greets every element in it with "Hello" followed by a newline.
mport java.util.*;
public class LabChallenge {
//add code below this line
//add code above this line
public static void main(String args[]){
ArrayList names = new ArrayList();
for (String s : args){
names.add(s);
}
sayHello(names);
}
}
Hint : You can start your method with public static void sayHello(ArrayList variable). Then iterate through variable using a loop in order to print Hello to each element in variable. You can also review the reading question in "Alternative Parameters" in the "Parameters" assignment.
Requirements:
Don't change the exisitng code
You can use any number of additional methods youd like but you must include at least the method called sayHello() in your code.
Compile and test your code with different value :
1. Compile and test with Alan and Bob
Expected output : Hello Alan
Hello Bob
2. Compile and test with 1,2,3
Expected output:
Hello 1
Hello 2
Hello 3
Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!