Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2008, 07:56 AM
Member
 
Join Date: Jul 2008
Posts: 10
Unknown1369 is on a distinguished road
while loop
hi, i am having a bit of a problem. i'm a newb when it comes to programming, especially java. i need to know how to start this problem.

public class printContact {

public static final int MAX_ENTRIES = 10;
public static int curr_entries = 6;
public static String[] first_names = {"Stan","Fredia","James","Sandra","Jerry","Robin"} ;
public static String[] last_names = {"Marko","Zells","Johnson","Christmas","kelly","By rde"};
public static String[] street_address = {"2 Easy Street","23 King Junction","10207 W. OuttaMy Way","18 Walker Blvd","00 Memory Lane","16 Lovers Lane"};
public static String[] city = {"Ann Arbor","Ypsilanit","Belleville","Dexter","Maumee", "Toledo"};
public static String[] state = {"Michigan","Michigan","Michigan","Michigan","Ohio ","Ohio"};

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}


1. On the first line, separated by space, print first name and last name.
2. On the second line the street address.
3. On the third line, separated by a comma and a space, write out the city and state.

Since the information is stored in parallel arrays use a while loop to print out the information. Use integer variables to index the arrays and also use integer(s), boolean(s) and/or constants to terminate the while loop. Do not use hard coded numeric values in the code except to initialize constants or variables.

thank you.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-08-2008, 09:06 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Simply do something like this.

Code:
int i = 0; while(i < curr_entries) { System.out.println(first_names[i] + " " + last_names[i]); System.out.println(street_address[i]); System.out.println(city[i] + ", " + state[i] + "\n"); i++; }
It's better to refer some documents about loops. It's not specific to Java, in every language you have.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-08-2008, 09:26 AM
Member
 
Join Date: Jul 2008
Posts: 10
Unknown1369 is on a distinguished road
thank you. i sorta understand most of it. don't understand how you came up with "curr_entries" tho.

anyways, another question.

Includes a function (method), called from "main" that adds your own first name and last name and fictitious contact information to the end of the parallel arrays


i have this written up:

System.out.print("John");
System.out.print(" ");
System.out.println("Doe");
System.out.println("1 Washington Street");
System.out.print("Detroit");
System.out.print(", ");
System.out.println("Michigan");

is this correct? or is there a simpler way to do it instead of repeating "System.out.print"?

Thanks again.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-08-2008, 09:43 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Code given by Eranga does the same what u r asking for. That code adds your own first name and last name and fictitious contact information. If u want to add 1 more detail add it to the array instead of doing sysout's everytime...

If u r not comfortable with while loop(easiest) u can even go for using FOR loop.
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-08-2008, 09:45 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
System.out.print not added any values into the arrays. Just run and see what happened.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-08-2008, 12:15 PM
Member
 
Join Date: Jul 2008
Posts: 10
Unknown1369 is on a distinguished road
thank you both. that helps alot.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use Do While loop Java Tip java.lang 0 04-17-2008 09:45 PM
How to use While loop Java Tip java.lang 0 04-17-2008 09:44 PM
do...while loop eva New To Java 16 01-31-2008 08:44 AM
can you help me with this for loop? java_fun2007 New To Java 6 12-22-2007 12:20 PM
A loop that doesn't loop MichYer New To Java 2 07-30-2007 10:44 AM


All times are GMT +3. The time now is 01:50 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org