Source: http://www.imooc.com/code/1306
The conditional operator (? :) also known as the ternary operator.
Syntax form: boolean expression? Expression 1: Expression 2
Operation procedure: Returns the value of expression 1 If the value of the Boolean expression is true , otherwise returns the value of expression 2
For example:
Because the value of the expression 8>5 is true, the return
Task
Come and join the practice of the conditional operator!
Enter the code in the 4 line in the editor, applying the relational operator implementation "judgment: if score is greater than or equal to 60, the output is passed, and the output is not passed"
Operation Result:
1 Public class helloworld{2 Public Static void Main (string[] args) {3 int score=68; 4 String mark =5 System.out.println ("test Result:" +mark); 6 }7 }
1 Public class helloworld{2 Public Static void Main (string[] args) {3 int score=68; 4 String mark = (score >= 60)? "Pass": "Fail"; 5 System.out.println ("How the Exam results:" +mark); 6 }7 }
Web-android Engineer first form the conditional operator in -3-8 Java