Conditional operators in Java
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:
650) this.width=650; "src=" http://img.mukewang.com/535f7d130001a84f04340051.jpg "/>
Because the value of the expression 8>5 is true, return 650) this.width=650; "src=" http://img.mukewang.com/535f72e40001b34900570021.jpg "/>
Code:
public class helloworld{
public static void Main (string[] args) {
int score=68;
String mark = (score >=60)? " Pass ":" Failed ";
System.out.println ("How the Exam results:" +mark);
}
}
Operation Result:
Exam Results: Pass
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547679
Java Basics---Conditional operators in Java (15)