Dom R Dom R - 1 year ago 101
Java Question

Do-While loop to fill out Array

I am currently working on a project that asked me to set up data entry. In the data entry mode the user will be asked to enter the Scientists data in a loop. if the user responds with 'y' they will be prompted to enter another scientist. The best way I can think to do this is with a do-while loop to fill the array until the user decides its over. I am having trouble with

  1. filling the names into the array, and

  2. the program won't prompt for a name after the initial loop.

Here is what I have:

public class Scientist {
private String name;
private String field;
private String greatIdeas;

public static void main(String[] args) {
String scientists[] = new String[100];
int scientistCount = 0;
Scanner input = new Scanner(;

String answer;
System.out.println("Enter the name of the Scientist: ");

System.out.println("Would You like to add another Scientist?");


Answer Source

Change while("Y")); to while(input.nextLine().equalsIgnoreCase("Y"));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download