Good day to every one.

First here is my code so far

public class Program2 {
    public static void main (String[]args) throws IOException{
        BufferedReader bv = new
                BufferedReader (new InputStreamReader(;
        String a, b, c, x;
        Float d, e, f, g, h, i, j, k, l, m, ave;

        System.out.println("ENTER FIRSTNAME: ");
        a = bv.readLine();

        System.out.println("ENTER LASTNAME: ");
        b = bv.readLine();

        System.out.println("ENTER COURSE: ");
        c = bv.readLine();

        System.out.println("------  GRADE  -------");

        System.out.println("SUBJECT1 : ");
        x = bv.readLine();
        d = Float.parseFloat(x);

        System.out.println("SUBJECT2 : ");
        x = bv.readLine();
        e = Float.parseFloat(x);

        System.out.println("SUBJECT3 : ");
        x = bv.readLine();
        f = Float.parseFloat(x);

        System.out.println("SUBJECT4 : ");
        x = bv.readLine();
        g = Float.parseFloat(x);

        ave = (d+e+f+g)/4;

        System.out.println("Your Average is: "+ave);

            System.out.println("HIGHEST : "+d);   
        else if (e>d&&e>f&&e>g){
            System.out.println("HIGHEST : "+e);   
        else if (f>d&&f>e&&f>g){
            System.out.println("HIGHEST : "+f);   
        else if (g>d&&g>e&&g>f){
            System.out.println("HIGHEST : "+g);   

            System.out.println("LOWEST : "+d);   
        else if (e<d&&e<f&&e<g){
            System.out.println("LOWEST : "+e);   
        else if (f<d&&f<e&&f<g){
            System.out.println("LOWEST : "+f);   
        else if (g<d&&g<e&&g<f){
            System.out.println("LOWEST : "+g);   

        if (ave>=75){
            System.out.println("REMARKS : PASSED");

            System.out.println("REMARKS : FAILED");


Now here is my problem:
i am going to enter 15 subjects grade.
what if there is two or more lowest or highest grades what should i do?
there must be only one highest and lowest grades.

here is the output:

Enter FirstName:
Enter LastName:
Enter Course:
The Average is:
Highest Grade is:
Lowest Grade is:

thanks in advanced.

Recommended Answers

All 3 Replies

Well in case you have more grades the same you should print a message saying that the student got the lowest grade on 2 or more subjects.
You should modify your code like this:

  int highGrades =0;
        float highGrade =0;

        int lowGrades = 0;
        float lowGrade = 0;

            highGrade = d;
         if (e>=d&&e>=f&&e>=g){
              highGrade = e;
         if (f>=d&&f>=e&&f>=g){
              highGrade = f;
         if (g>=d&&g>=e&&g>=f){
              highGrade = g;

        System.out.println("You got the highest grade " + highGrade + " at " + highGrades + " subjects");

So, instead of finding only one highest grade we take all into consideration and we count them as well. Also we then print out what is the highest grade and at how many subjects we got it.
The same applies to the lowest grade.

commented: thanks for the help.. +0

This sounds like a problem with the specification, not with your Java!
In reality there can always be two or more equal "highest" grades (eg supose Mr Genius scores 100% on every subject). You have a choice of just printing one of them or printing them all. In real life you would probably have to print all the equal highest grades, but maybe your teacher wants something different, or maybe because this is a beginner class you can assume all the grades are different and forget about this problem for now. You need to ask your teacher.

thanks Mike+9

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.