Simple Java Program 9: Pass Or Fail Using If-Else

Using the if-else statement, this simple program asks the user to input a number and it will display either Pass or Fail.
Passing score is 50 and above. If you input any number below 50, it displays Fail.

import java.util.Scanner;
public class PassFail {

public static void main(String[] args) {
int num;
Scanner reader = new Scanner(System.in);
System.out.println("Enter score: ");
num = reader.nextInt();

if (num>=50)
{
System.out.println("Pass!");
}
else
System.out.println("Fail!");
}

}

Here's the output:

Comments

  1. //Check whether the student is passed or failed and if he got passed print which rank obtained.

    package com.programs.mss;
    import java.util.Scanner;

    public class demo5 {

    public static void main(String[] args) {
    int num;
    Scanner reader = new Scanner(System.in);
    System.out.println("Enter score: ");
    num = reader.nextInt();
    if (num>90)
    {
    System.out.println("pass");
    System.out.println("1st rank!");
    }
    else if (num>80)
    {
    System.out.println("pass");
    System.out.println("2nd rank!");
    }
    else if (num>70)
    {
    System.out.println("pass");
    System.out.println("3rd rank!");
    }
    else if (num>60)
    {
    System.out.println("pass");
    System.out.println("4th rank!");
    }
    else if (num>50)
    {
    System.out.println("pass");
    System.out.println("5th rank!");
    }

    else if (num<50)
    {
    System.out.println("Fail!");
    System.out.println("Better luck next time...!!!");
    }

    }}

    ReplyDelete
  2. Please answer this please help!

    Make a program that wi determine if the student pass or fail in subject passed on grading scheme
    30% quizzes
    30% written exam
    40% paractical exam
    Passing grade 75%

    ReplyDelete
  3. it was helpful for me thanks......





















    ReplyDelete
  4. how to write the same program for multiple inputs

    ReplyDelete
  5. if i have give the marks in any one subject below 30 how to get result fail??

    ReplyDelete
  6. Please help me to answer this question

    ReplyDelete
  7. Workday HCM Certification Training
    The Workday HCM certification training provides a complete understanding of Workday concepts and helps you prepare for global certification exams.

    ReplyDelete

Post a Comment