I have a school project and what is needed is to Write a program that prompts the instructor to enter the 10 grades of midterm 1 and store these numbers in an array. Next prompt for the 10 grades of midterm 2 and store these numbers in a different array. Next prompt for the 10 grades of the Final Exam and store these in a different array. Next add midterm1 to midterm2 to Final and store the totals in a different array. Next, scan the array that has the totals and identify the minimum grade and maximum grade. Inform the instructor of the minimum grade and maximum grade.

The problem is i cannot get the min to work right. Right now just using 3 array indexes when this gets working then i will use the 10.

Thanks for the Help.

package assign6_sb;
import java.util.*;
public class Assign6_SB {

    public static void main(String[] args) {
       
        Scanner SC = new Scanner(System.in);
        int[] midterm1 = new int[2];
         int[] midterm2 = new int[2];
          int[] fExam = new int[2];
           int[] total = new int[2];
       
          int m1Collect;
           int m2Collect;
            int fexCollect;
             int max = total[0];
             int min = total [0];
               int counter1 = 0;
               int counter2 = 0;
               int counter3 = 0;
          //fill midterm1              
          for(int index = 0; index < midterm1.length; index++)
          {              
               counter1++;
              System.out.println("Enter the grades for midterm 1: Student: "+counter1);
              m1Collect = SC.nextInt();              
              midterm1[index] = m1Collect;           
          }
          //fill midterm2
          for(int index = 0; index < midterm2.length; index++)
          {               
               counter2++;
              System.out.println("Enter the grades for midterm 2: Student: "+counter2);
              m2Collect = SC.nextInt();            
              midterm2[index]=m2Collect;                       
          }
          //fill fExam
          for(int index = 0; index < fExam.length; index++)
          {             
             counter3++;
              System.out.println("Enter the grades for the final exam: Student: "+counter3);
              fexCollect = SC.nextInt();            
              fExam[index]=fexCollect;
              
          }
        
            for (int index = 0; index < total.length; index++)
       {
            
            total[index] = (midterm1[index] + midterm2[index] + fExam[index]);   
       }
          
       for (int index = 0; index < total.length; index++)
       {          
           if(total[index] > max)
              max = total[index];       
       
        }   

          for (int index = 0; index < total.length; index++)
        {            
            if(total[index] < min)            
                min = total[index];           
        }       
          
       
       System.out.println("This is the Max " + max);
       System.out.println("This is the Min " + min);
        
    }
}

>>int min = total [0];

there's not gonna be a value less than 0
why don't you set min as the first value of the array after the array is filled

Okay thanks Zeroliken for the input it cleared up my over thinking.

here is the completed code just for anyone to reference.

package assign6_sb;
import java.util.Scanner;
public class Assign6_SB {

    public static void main(String[] args) {
       //arrays
        Scanner SC = new Scanner(System.in);
        int[] midterm1 = new int[10];
         int[] midterm2 = new int[10];
          int[] fExam = new int[10];
           int[] total = new int[10];
       //collections
          int m1Collect;
           int m2Collect;
            int fexCollect;
             //counter for student
               int counter1 = 1;
                int counter2 = 1;
                 int counter3 = 1;
              
               
          //fill midterm1              
          for(int index = 0; index < midterm1.length; index++)
          {
              System.out.println("Enter the grades for midterm 1: Student: "+counter1);
              m1Collect = SC.nextInt(); 
              counter1++;
              midterm1[index] = m1Collect;           
          }
          //fill midterm2
          for(int index = 0; index < midterm2.length; index++)
          { 
              System.out.println("Enter the grades for midterm 2: Student: "+counter2);
              m2Collect = SC.nextInt(); 
              counter2++;
              midterm2[index]=m2Collect;                       
          }
          //fill fExam
          for(int index = 0; index < fExam.length; index++)
          { 
              System.out.println("Enter the grades for the final exam: Student: "+counter3);
              fexCollect = SC.nextInt();   
              counter3++;
              fExam[index]=fexCollect;
              
          }
        //fill the total with the summed values
            for (int index = 0; index < total.length; index++)
       {    
            total[index] = (midterm1[index] + midterm2[index] + fExam[index]);            
       }
            //fill the min and max with the first index
           int max = total[0];
           int min = total[0];
              
           //find the min and max
       for (int index = 0; index < total.length; index++)
           
       {          
           if(total[index] > max)
              max = total[index];
           if(total[index] < min)            
                min = total[index];  
        }   
       
       System.out.println("The maximum grade is " + max);
       System.out.println("The minimum grade is " + min);
        
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.