I have a program that is meant to display the total, average, student name and letter grade for a student. I'm almost done writing it but I have no idea how to make it loop so it goes back to step 1 from step 4. Everything I've read on using "while" loops hasn't really been helpful to me with this particular application.

import java.util.Scanner;

public class Averages5 {

 public static void main(String[] args) {

        // variable declaration 

        String name;
        int mark1, mark2, mark3 ;
        int grade = 0;
        int A, B, C, F;

        double average;
        // input
        Scanner input = new Scanner(System.in);
        System.out.println("Enter Your Name");
        name = input.nextLine();

        Scanner marks = new Scanner(System.in);
        System.out.println("Enter The Student's Grades");
        mark1 = input.nextInt();
        mark2 = input.nextInt();
        mark3 = input.nextInt();
        int total = mark1 + mark2 + mark3;
System.out.println("The total of the three numbers is: " + total);

        input.close();
        average = (double) (mark1 + mark2 + mark3) / 3;
        System.out.println("Your average from the three grades is " + average);

        if (average >= 90 && grade <= 100) {
            System.out.println("Your Grade is A");
        } else if (average >= 80 && grade <= 89.99) {
            System.out.println("Your Grade is B");
        } else if (average >= 70 && grade <= 79.99) {
            System.out.println("Your Grade is C");  
        } else if (average >= 0 && grade <= 79.98) {
           System.out.println ("Your Grade is F");
        }
        System.out.println("The Student's name is: " + name);
    }
}

Recommended Answers

What are the steps you refer to in your code? Adding comments to your code, to clarify this would help.

Jump to Post

All 2 Replies

What are the steps you refer to in your code? Adding comments to your code, to clarify this would help.

Is this really answered? If not mark it "unsolved" and someone will help.

Be a part of the DaniWeb community

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