Conditional operator: ?

This example reads in a grade and prints pass or fail.

1
2
3
4
5
6
7
8
9
10
11
12
// Pass fail
package grades;
import java.util.*;
public class PassFail {
  public static void main(String[] args) {
    Scanner keyboard=new Scanner(System.in); //do just once
    int grade;
    System.out.print("Enter a grade:");
    grade=keyboard.nextInt();
    System.out.println((grade<65)? "fail": "pass");
  }//main
}//class
CODE

Sample output:

Enter a grade:65
pass

Enter a grade:64
fail

NEXT: