Hi,
The whole idea of this program is allow teachers to input marks results for 6 students. Once all marks have been entered, It must to display the marks and grade for each student.

For some reason it can't display the grade properly.
It just display "Fail" on each mark.
If somebody can help me, I'd appreciate.
Thank you.

import java.util.Scanner;

public class ExamMarks
{
   public static void main(String[] args)
   {
      int marks = 0;
      String g = "";
      int[] sNumb = new int[6];             
      Scanner scan = new Scanner(System.in);

     
       for (int i = 0; i < sNumb.length ; i++) 
       {
           System.out.println("Enter mark of student " + (i+1) ); //increment int by one
           sNumb[i]= scan.nextInt();
       } 
         
       for (int i = 0; i < sNumb.length ; i++)
       {
               if (marks <= 39)
               {
                   g = "Fail";
               }
               
               else
               
               if (marks >= 40 && marks <= 64)
               {
                   g = "Pass";
                   System.out.println(" Student " + (i + 1) + " received a mark of " + sNumb [i]  + " and a " + g + " grade ");
                   
               }
               
               else
               
               if (marks >= 65 && marks <= 84)
               {
                   g = "Merit";
                   System.out.println(" Student " + (i + 1) + " received a mark of " + sNumb [i]  + " and a " + g + " grade ");
               }
               
               else
              
               if (marks >= 85 && marks <= 100)
               {
                   g = "Distinction";
                   System.out.println(" Student " + (i + 1) + " received a mark of " + sNumb [i]  + " and a " + g + " grade ");
               }
              
            
               System.out.println(" Student " + (i + 1) + " received a mark of " + sNumb [i]  + " and a " + g + " grade ");
       }
 
 
    }
}

Recommended Answers

All 2 Replies

In line 7, you initialize "marks" variable to 0. In line 21, you use it right away without assigning the input. As a result, all marks you are comparing are always 0. You don't need "marks" variable. What you need is to replace all "marks" variable with sNumb from line 21 and after.

In line 7, you initialize "marks" variable to 0. In line 21, you use it right away without assigning the input. As a result, all marks you are comparing are always 0. You don't need "marks" variable. What you need is to replace all "marks" variable with sNumb from line 21 and after.

Thank you very much, Taywin. Now my program is working properly!!

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.