– One Dimensional Array
Consider this example problem: You are given 7 quiz scores of a student. You are to compute the final quiz score, which is the sum of all scores after subtracting the lowest one.
For example, if the scores are
8 7 8.5 9.5 7 5 10
then the final score is 50.
double[] score = {8, 7, 8.5, 9.5, 7, 5, 10};
Double min = 10; //the highest possible score is 10
Double total = 0;
for(int i = 0; i < score.length; i++)
{
total += score[i];
if(score[i] < min)
{
min = score[i];
}
}
total -= min;
System.out.println("Total = " + total);
Oh, all the doubles have to be lower case.
thank you..:)
To solve this problem, you can use a one-dimensional array and follow these steps:
1. Declare an array of size 7 to store the quiz scores.
In this case, the array will be [8, 7, 8.5, 9.5, 7, 5, 10].
2. Find the lowest score in the array.
- Initialize a variable called "lowest" to store the lowest score. Set it to the maximum possible value (e.g., infinity).
- Iterate through each score in the array using a loop.
- Compare each score to the current lowest score. If a score is lower, update the value of the "lowest" variable.
3. Calculate the sum of all scores except the lowest one.
- Initialize a variable called "sum" to store the running sum. Set it to 0.
- Iterate through each score in the array using a loop.
- If the score is not equal to the lowest score, add it to the "sum" variable.
4. Print the final score.
- Output the value stored in the "sum" variable.
Following these steps with the provided example scores, you would get the final score of 50.