I can prompt the user for names and have my do
while
continue
to ask them for the names but I have no idea how to store them into an ArrayList
. I have seen a few examples but they all require the user to input a set number of elements.
I just need to prompt the user to input names, then continuously ask and prompt the user to input more names. Then eventually print all the names. Until the user types N
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<People> list = new ArrayList<People>();
String a = "";
do{
System.out.println("Enter your first and last name: ");
String name1 = scan.nextLine();
System.out.println("Would you like to enter another name? (Y/N)");
a = scan.nextLine();
}
while(a.equalsIgnoreCase("Y"));
}
}