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-09-2007, 08:36 PM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
Help with Structure
Write a short program in java to iterate over a structure and print out the names of all users which have a score less than 70.
At the end of the structure, also print out the average score of all users who scored 70 or higher.
Assume a global function/procedure called print which prints all parameters passed to it and that the structure is called Structure.

Code:
Structure Prototype = [[Name1, Score1], [Name2, Score2], …] Example Structure = [[‘Tim’, 98], [‘Tom’, 80], [‘Mike’, 50], [‘Jason’, 25]] Example Output = Mike Jason 89
Thanks
Albert
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-13-2007, 05:27 PM
Member
 
Join Date: Jul 2007
Posts: 44
susan is on a distinguished road
Whilst iterating over the whole collection you should do two things. Firstly you print out the names of everyone who got less than 70, and secondly you should add up the scores of all the people who got more than 70 and at the same time you increment a value

Code:
int averageCount; int totalAmount; for(int i = 0; i < collection amount; i++) { if(userScore[i] < 70) System.out.print(userScore[i]); else { totalAmount += userScore[i]; averageCount++; } } System.out.println("Average of those who scored higher than 70 is: " + (totalAmount/averageCount * 100));
That's roughly how I personally think it should work. Mind you, I haven't coded in yonks so I could be wrong

As for the two dimensional array, I'm sure you can figure that part out, it's simple enough to extract the correct value
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
Queue data structure Java Tip java.lang 0 04-14-2008 10:35 PM
Java Array of Structure PAffiliates New To Java 1 01-28-2008 08:08 AM
data structure code vgvt New To Java 1 01-17-2008 04:49 PM
Control Structure Question ibanez270dx New To Java 1 11-13-2007 12:10 AM
Use if then else structure, help paul New To Java 1 08-07-2007 07:00 AM


All times are GMT +3. The time now is 10:19 AM.


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