# loop

• March 8th, 2014, 08:42 PM
tamaljordan
loop
can somebody help me to solve this issue below ?

• Using a loop, write a program that takes 10 values representing exam grades (between 0 and 100) from the keyboard and output the minimum value, maximum values, and average value of all the values entered. Your program should not accept values less than 0 or greater than 100.

• Your program should neatly display the results. You are free to decide how you want the display to look. One possible output is shown below

Enter ten scores between 0 and 100.
Score 1: 45
Score 2: 94
Score 3: -3
Score 3: 85

Score 10: 88
Minimum score: 45
Maximum score: 94
Average score: 78.0
• March 8th, 2014, 09:34 PM
copeg
Re: loop
• March 8th, 2014, 09:34 PM
KucerakJM
Re: loop
^---copeg got it before me
redundant so I removed it.
• March 9th, 2014, 12:01 AM
tamaljordan
Re: loop
This is it, it is incomplete because I am stuck, about the condition

import java.util.Scanner;

/**
*
* Program to demonstrate looping.
*
*/
public class LoopProject6 {
public static void main(String[] args) {
// In this section of the program we will use
// a while loop that takes values
// (between 0 and 100) inclusive from the keyboard

// for loop used since whe know how many times(10 times) we need to loop
// We need a sum to accumulate values into.
// And it needs to be initialized.

int sum = 0;

float average;
double Max = 0;

double Min = 101;

Scanner console = new Scanner(System.in);
System.out.println("Enter ten scores between 0 and 100");

for (int score =1; score<= 10; score ++)
{
System.out.print("score" + score+ ":");
score= console.nextInt();
}

{
}
if (score > Minimum)
score= Minimum;
{
System.out.println("Minimum score: " ) ;
}
if (score < Maximum)
score= Maximum;
{
System.out.println("Maximum score: " );
}
average = sum / 10;
{
System.out.println("Average score: " );
}
}
}
• March 9th, 2014, 04:45 AM
GregBrannon
Re: loop
Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.
• March 9th, 2014, 08:30 AM
tamaljordan
Re: loop
Code Java:

```  import java.util.Scanner;     /** * * Program to demonstrate looping. * */ public class LoopProject6 { public static void main(String[] args) { // In this section of the program we will use // a while loop that takes values // representing exam grades // (between 0 and 100) inclusive from the keyboard   // for loop used since whe know how many times(10 times) we need to loop // We need a sum to accumulate values into. // And it needs to be initialized.   int sum = 0;   float average; double Max = 0;   double Min = 101;   Scanner console = new Scanner(System.in); System.out.println("Enter ten scores between 0 and 100");     for (int score =1; score<= 10; score ++) { System.out.print("score" + score+ ":"); score= console.nextInt(); }   { System.out.println("Invalid score.Please try again"); } if (score > Minimum) score= Minimum; { System.out.println("Minimum score: " ) ; } if (score < Maximum) score= Maximum; { System.out.println("Maximum score: " ); } average = sum / 10; { System.out.println("Average score: " ); } } }```

--- Update ---

Thanks, I posted it as you asked
• March 9th, 2014, 08:58 AM
KucerakJM
Re: loop
So there are a few issues I can see:
1. The counter variable for your for loop (score) is the same variable you use to get input, rendering the counter useless.
2. The variable score has a scope restricted to the for loop and is therefore not accessible outside of it.
3. minimum and maximum are never declared as variables anywhere.

I suggest getting a single portion of this assignment working first such as getting input for the 10 scores (making sure they are between 0-100). After that move onto either min score, max score, or average. If the for loop ends up giving you some troubles there are always other types of loops so keep that in mind.

Perhaps go over this: The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)
and this (just in case): The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

Forgot to mention you may want to look over java syntax rules as you have a lot of unnecessary curly braces.