Advertisement
Spocoman

03. Passed or Failed

Oct 15th, 2024 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class PassedOrFailed {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double grade = Double.parseDouble(scanner.nextLine());
  7.        
  8.         if (grade >= 3) {
  9.             System.out.println("Passed!");
  10.         } else {
  11.             System.out.println("Failed!");
  12.         }
  13.     }
  14. }
  15.  
  16. Solution with ternary operator:
  17.  
  18. import java.util.Scanner;
  19.  
  20. class PassedOrFailed {
  21.     public static void main(String[] args) {
  22.         Scanner scanner = new Scanner(System.in);
  23.         double grade = Double.parseDouble(scanner.nextLine());
  24.        
  25.         System.out.println(grade >= 3 ? "Passed!" : "Failed!");
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement