27 lines
519 B
Java
27 lines
519 B
Java
![]() |
//: operators/TernaryIfElse.java
|
|||
|
// <20>2015 MindView LLC: see Copyright.txt
|
|||
|
import static com.mindviewinc.util.Print.*;
|
|||
|
|
|||
|
public class TernaryIfElse {
|
|||
|
static int ternary(int i) {
|
|||
|
return i < 10 ? i * 100 : i * 10;
|
|||
|
}
|
|||
|
static int standardIfElse(int i) {
|
|||
|
if(i < 10)
|
|||
|
return i * 100;
|
|||
|
else
|
|||
|
return i * 10;
|
|||
|
}
|
|||
|
public static void main(String[] args) {
|
|||
|
print(ternary(9));
|
|||
|
print(ternary(10));
|
|||
|
print(standardIfElse(9));
|
|||
|
print(standardIfElse(10));
|
|||
|
}
|
|||
|
} /* Output:
|
|||
|
900
|
|||
|
100
|
|||
|
900
|
|||
|
100
|
|||
|
*///:~
|