Results 1 to 3 of 3
Thread: Array problem
- 12-18-2010, 07:44 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Array problem
Hello,
I am trying to write code to store integers (scores), print them out, and then display the number of scores entered. However, if you enter 3 integers it displays the 3 you entered, 2 zero's, and then tells you you entered 4 scores?! Im very confused here and have tried various if statements, loops, decrementors, etc and I am still at a loss for a solution.
Any help would be appreciated!!
Java Code:import javax.swing.*; public class Scores { private final static int SIZE = 25; public static void main(String[] args) { int [] scores = new int[SIZE]; int count = 0; double average = 0.0; count = loadArray(scores); average = determineAverage(scores, count); displayResults(scores, count, average); System.exit(0); } //returns the count of the scores entered private static int loadArray(int[]n) { int s = 0; int i; s = Integer.parseInt(JOptionPane.showInputDialog(null, "Input test score")); if(s == -1){ break ; } else { n[i] = s; i++; } return(i+1); // so file compiles } //displays all of the results private static void displayResults(int[] n, int cnt, double ave) { for(int i = 0; i<=cnt; i++){ System.out.println(n[i]); if(n[i]%10 == 0){ System.out.println(); } } System.out.println("The total number of test scores" + cnt); // int outstanding = determineOutstanding(0); //System.out.println("The number of Outstanding Scores" + outstanding); }
- 12-19-2010, 02:17 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
variable int count is not an array
- 12-19-2010, 03:26 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
And also if this is the complete class you've written, seems to me that you've not compile the code.
1. Closing bracket of the class is missing.
2. I can't see the method determineAverage is implemented in your class.
3. In loadArray I can't see that variable i is not initialize before use.
Don't you notice those things?
Similar Threads
-
Array problem please help
By newToJava3 in forum New To JavaReplies: 2Last Post: 12-15-2010, 12:38 PM -
Problem with Array Use
By Mike90 in forum New To JavaReplies: 1Last Post: 06-02-2010, 02:45 PM -
Array problem
By c3jcarmy in forum New To JavaReplies: 11Last Post: 03-11-2010, 02:45 AM -
array problem
By oceansdepth in forum New To JavaReplies: 3Last Post: 04-05-2008, 02:25 AM -
array problem
By Albert in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 01:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks