I am working on an array that stores a string of name and an integer of age, I want the array to be a max of 4 and print out these results, unless the user enters the word 'done', if so the program terminates and the array outputs what it has stored.
The array works fine but can't seem to get the 'done' section, that I am currently using an if statement with .equals
any suggestions?
Thanks
import java.util.Scanner;
import java.util.ArrayList;
public class NameAge1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);
final int MAX_VALUE = 4;
boolean name = false;
ArrayList<String> nameList = new ArrayList<>();
ArrayList<Integer> ageList = new ArrayList<>();
Integer[] ages = new Integer[4];
for(int i = 0; i < MAX_VALUE; i++ ) {
if(name = true) {
System.out.print("Enter a name: ");
nameList.add(input.nextLine());
if (nameList.equals("DONE")) {
break;
}
System.out.print("Now enter an age for " + nameList.get(i) + ": ");
ageList.add(input2.nextInt());
}
}
Aucun commentaire:
Enregistrer un commentaire