My Bookmarks

  • No bookmark found

Most Active Members

Write a program to print grades for given input percentage from command line using nested if else in Java1 min read

AIM: – Write a program to print grades for given input percentage from command line using nested if else.

Here we are writing about Write a program to print grades for given input percentage from command line using nested if else in Java. Our initiative is that user understand code by reading comment so that he/she can became capable to any understand code in this programming world.

Source Code: –

import java.util.Scanner;

public class Grade {

    public static void main(String[] args) {

        double percent;
        Scanner scanner = new Scanner(System.in);

        /*Reading the percentage of student from the command line
        * using nextDouble(method provided by Scanner class)
        * which returns the next token as a double value
        */
        System.out.print("Enter the percentage of student:- ");
        percent = scanner.nextDouble();

        /*Checking the percentage of the student and printing
        * the grade accordingly using the if else ladder
        */
        if(percent > 90) {
            System.out.println("Grade is A+");
        } else if(percent < 90 && percent >= 80) {
            System.out.println("Grade is A");
        } else if(percent < 80 && percent >= 70) {
            System.out.println("Grade is B+");
        } else if(percent < 70 && percent >= 60) {
            System.out.println("Grade is B");
        } else if(percent < 60 && percent >= 50) {
            System.out.println("Grade is C");
        } else {
            System.out.println("Grade is F");
        }
    }
}

Output:

Bookmark(0)
Tags:

Add a Comment

Your email address will not be published. Required fields are marked *