View Single Post
  #1 (permalink)  
Old 07-24-2007, 02:23 AM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
Help with string and array in java
Hi, OK so for example you run the script, and put in the names, john, tom, andrew.
Code:
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?

Code:
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
Reply With Quote
Sponsored Links