Hi, OK so for example you run the script, and put in the names, john, tom, andrew.
john should be array[0].firstname
tom should be array[1].firstname
andrew should be array[2].firstname
I don't understand why it doesn't print those all out again for you. Instead i get tom repeated 3x
Could you explain what i am doing wrong?
import java.io.*;
public class PhoneBook {
final static int nocont = 3;
static Contact[] array = new Contact[3];
public static void main(String[] args) {
for (int i = 0; i < nocont; i++){
array[i] = new Contact();
System.out.println("Enter first name: ");
array[i].firstname = UserInput.readString();
}
for(int j = 0; j < nocont; j++)
System.out.println(array[j].firstname);
}
}
Thanks