Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need assistance with a code I'm developing

I don't have the info for making if-else nest with input and output. See if you can help me, with putting the right code so the compiler reads what I'm trying to execute

Comments

  • JakeXSVJakeXSV Member Posts: 2
    Here is a easy example of nested if statements
    This calculates the letter grade based on the percent entered.
    btw, not sure if those percents are the actual academic numbers used...

    [code]public class IFStatements {
    int percent;

    Scanner scan = new Scanner(System.in);
    System.out.println("Enter your percent 0-100");
    percent = scan.nextInt();

    if(percent>69)
    //if the value is not greater than 69, it jumps down to the else and displays a F
    {
    if(percent>75)
    //if the value is not greater than 75, it jumps down to the else and displays a D
    {
    if(percent>85)
    //if the value is not greater than 85, it jumps down to the else and displays a C
    {
    if(percent>93)
    //if the value is not greater than 93, it jumps down to the else and displays a B, but if it is greater, its an A
    {
    System.out.println("A");
    }
    else
    {
    System.out.println("B");
    }
    }
    else
    {
    System.out.println("C");
    }
    }
    else
    {
    System.out.println("D");
    }
    }
    else
    {
    System.out.println("F");
    }
    }
    }
    [/code]
Sign In or Register to comment.