Results 1 to 2 of 2
- 07-24-2007, 12:23 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Help with string and array in java
Hi, OK so for example you run the script, and put in the names, john, tom, andrew.
I don't understand why it doesn't print those all out again for you. Instead i get tom repeated 3xJava Code:john should be array[0].firstname tom should be array[1].firstname andrew should be array[2].firstname
Could you explain what i am doing wrong?
ThanksJava 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); } }
- 08-07-2007, 06:12 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
Convert a vector to a string array
By orchid in forum New To JavaReplies: 4Last Post: 02-24-2010, 02:31 AM -
How i add string array in vector
By susan in forum New To JavaReplies: 7Last Post: 02-12-2009, 01:32 PM -
JSP to output Java String Array
By irenavassilia in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-31-2008, 04:11 PM -
String []Array
By Warren in forum New To JavaReplies: 4Last Post: 12-01-2007, 08:03 AM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks