Solution for Exercise CheckPassFail

Compiled By Unknown - No Comments
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public class CheckPassFail { // saved as "CheckPassFail.java"
   public static void main(String[] args) {
      int mark = 50;         // set the value of mark here!
      System.out.println("The mark is " + mark);
 
      if ( mark>=50 ) {
         System.out.println("Congratulations, You Are Passed and you obtained "+ mark+ " Marks" );
      } else {
         System.out.println("Sorry You are failed, you obtain "+ mark +" Marks");
      }
   }
}


Solution for Exercise CheckPassFail are solved in two cases. First is without Scanner and second is with Scanner.
If you want to input number yourself try following.
import java.util.Scanner;

public class CheckPassFail { 
   public static void main(String[] args) {
      int n1;
      Scanner mark=new Scanner(System.in);
      
      System.out.println("Write the Marks you obtain : ");
      n1=mark.nextInt();
 
      if ( n1>=50 ) {
         System.out.println("Congratulations, You Are Passed and you obtained "+ n1+ " Marks" );
      } else {
         System.out.println("Sorry You are failed, you obtain "+ n1 +" Marks");
      }
   }
}

Tags:

No Comment to " Solution for Exercise CheckPassFail "