Results 1 to 2 of 2
Thread: Help with Structure
- 07-09-2007, 06:36 PM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
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.
ThanksJava Code:Structure Prototype = [[Name1, Score1], [Name2, Score2], …] Example Structure = [[‘Tim’, 98], [‘Tom’, 80], [‘Mike’, 50], [‘Jason’, 25]] Example Output = Mike Jason 89
Albert:rolleyes:
- 07-13-2007, 03:27 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 44
- Rep Power
- 0
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
That's roughly how I personally think it should work. Mind you, I haven't coded in yonks so I could be wrongJava 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));
As for the two dimensional array, I'm sure you can figure that part out, it's simple enough to extract the correct value
Similar Threads
-
Queue data structure
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:35 PM -
Java Array of Structure
By PAffiliates in forum New To JavaReplies: 1Last Post: 01-28-2008, 06:08 AM -
data structure code
By vgvt in forum New To JavaReplies: 1Last Post: 01-17-2008, 02:49 PM -
Control Structure Question
By ibanez270dx in forum New To JavaReplies: 1Last Post: 11-12-2007, 10:10 PM -
Use if then else structure, help
By paul in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks