# Array problem

**807600**Nov 13, 2007 12:16 AM

I am trying to add the numbers in the array. if I put in 1,2,3,4,5,6,7 the total should be 28 but for some reason I am getting 21.

Here is what I have:

Here is what I have:

```
import java.util.Scanner;
public class Diving
{
public static void main(String[] args)
{
double[] scores = new double[7];
int posMinScore, posMaxScore;
double sum = 0;
double difficulty;
double finalscore = 0;
int index = 0;
double next = 0;
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter a degree of difficulty between 1.2"
+ " and 3.8: ");
difficulty = keyboard.nextDouble();
System.out.println("Enter 7 scores between 0 and 10: ");
next = keyboard.nextDouble();
posMaxScore = (int)scores[0];
posMinScore = (int) scores[0];
while ((next >= 0) && (next <= 10) && (index < scores.length - 1)
&& (difficulty >= 1.2) && (difficulty <= 3.8))
{
scores[index] = next;
index++;
next = keyboard.nextDouble();
if(scores[index] > posMaxScore)
posMaxScore = (int)scores[index];
if(scores[index] < posMinScore)
posMinScore = (int)scores[index];
finalscore = finalscore + scores[index];
}
for (index = 0; index < scores.length; index++)
{
finalscore = finalscore + scores[index];
}
System.out.println("The diver's final score is " + finalscore);
}
}
```

- 25 Views
- Tags: none (add)