Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Minimum and Maximum

843785Oct 6 2008 — edited Oct 6 2008
Alright, so I am asking for 10 inputs from a user that are 10 test grades from 0-100. Afterwards, i am supposed to output the minimum of the values, the maximum of the values, and the average. The problem is, when i compile and run the file, the minimum and maximum values come out as the same number...I'm not sure how else to write the program to fix that..hellppppp????!!
/* ExamGrades

 */
import java.util.*;
import java.text.*;


public class ExamGrades
{
  public static void main ( String [ ] args )
  {
    
    
    Scanner scan = new Scanner( System.in);
    DecimalFormat answer = new DecimalFormat( "#0.00");
    int grade;
    int min = 0;
    int max = 0;
    double total = 0;
    
    for( int i = 1; i <=10; i++)
    {
      System.out.print( "Please enter an exam grade between 0 and 100");
      
      grade = scan.nextInt();
      if ( grade >= 0 && grade <= 100)
      {
        max = grade;
        min = grade;
        
        
        total += grade;
        
        if( grade < min)
        {
          min = grade;
          
        }
        if ( grade > max)
        {
          max = grade;
        }
        
        
        
      }
    }
      double average = total / 10;
      System.out.println( "The minimun value of your exam grades is " + min);
      System.out.println( "The maximum value of your exam grades is " + max);
      System.out.println( "The average of your exam grades is " + answer.format(average));
      
      
      
    }
  }

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 3 2008
Added on Oct 6 2008
11 comments
133 views