Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 03-06-2008, 01:38 AM
Member
 
Join Date: Mar 2008
Posts: 2
d24706 is on a distinguished road
Help needed with java arrays code
Hello,

I hope someone can help me. I had to do the following assignment( i have most of it done just cant finish it off, question and source code below).

Question?
Write a Java program that asks the user to input the scores, as a percentage( e.g 87.4), of 10 students. The scores entered must be stored ina n array.

The programme must determine:

The lowest score and its equivalent grade (ie A,B,etc)
The highest " " " " "
The average score and its "

The bit i cant do is tie in the equivalent grade with the lowest highest and average score.

Code:
Code:
//Arrayofscores.java //This programme asks the user to enter 5 exam scores and store them in an array import java.text.*; public class Arrayofscores { public static void main(String args[]) { int [] scores = new int[10]; int smallest, highest,temp,total=0; double average =0.0; //ask the user to enter 10 scores for (int i = 0;i<= scores.length-1;i++) { System.out.print("\n\nEnter Score " + (i+1) + ": "); scores[i] = UserInput.getInt(); } //find the lowest score smallest = scores[0]; for (int i = 1; i <= scores.length-1;i++) if (scores[i] < smallest) smallest = scores[i]; System.out.println("\nThe lowest score is : " + smallest); //find the highest score highest = scores[0]; for (int i = 1; i <= scores.length-1;i++) if (scores[i] > highest) highest = scores[i]; System.out.println("\nThe highest score is : " + highest); //find the average score for (int i = 0; i<=scores.length-1;i++) total = total + scores[i]; average = total/10.0; System.out.println("\nThe average score is : " + average); } }
Any suggestions would be greatly appreciated!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-06-2008, 08:01 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
Code:
public class ArrayOfScores { public static void main(String[] args) { int[] scores = { 3, 7, 2, 5, 4 }; int smallest, highest, temp, total = 0; double average = 0.0; //find the lowest score smallest = Integer.MAX_VALUE; for (int i = 0; i < scores.length; i++) if (scores[i] < smallest) smallest = scores[i]; System.out.println("\nThe lowest score is : " + smallest); //find the highest score highest = -Integer.MAX_VALUE; for (int i = 0; i < scores.length; i++) if (scores[i] > highest) highest = scores[i]; System.out.println("\nThe highest score is : " + highest); //find the average score for (int i = 0; i < scores.length; i++) total = total + scores[i]; average = (double)total/scores.length; System.out.println("\nThe average score is : " + average); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-07-2008, 02:11 AM
Member
 
Join Date: Mar 2008
Posts: 2
d24706 is on a distinguished road
ok,i understand that part of the code,what i cant figure out is how the print out say "your highest mark is 94% and thats an a. I probably use an if else statement and call a new method but i cant seem to tie this in with the main method of the code which i already have
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
Java Programmers Needed - Indianapolis IN pegitha Jobs Offered 4 05-08-2008 07:36 PM
Java experts needed- 30 minute online Java projects michelle Jobs Offered 0 03-06-2008 12:47 AM
Java help needed jeneal New To Java 0 11-21-2007 04:04 AM
Java developers needed neoris Jobs Offered 0 11-19-2007 04:48 PM
Arrays in Java hiranya New To Java 3 07-30-2007 10:10 AM


All times are GMT +3. The time now is 10:24 PM.


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