Learn the Java TERNARY OPERATOR in 5 minutes! ❔

preview_player
Показать описание
#java #javatutorial #javacourse

public class Main {
public static void main(String[] args) {

// ternary operator ? = Return 1 of 2 values if a condition is true

// variable = (condition) ? IfTrue : IfFalse;

int number = 10;

String evenOrOdd = (number % 2 == 0) ? "EVEN" : "ODD";

}
}
Рекомендации по теме
Комментарии
Автор

public class Main {
public static void main(String[] args) {

// variable = (condition) ? IfTrue : IfFalse;

int score = 75;
int number = 10;
int hours = 13;
int income = 60000;

String passOrFail = (score >= 60) ? "PASS" : "FAIL";
String evenOrOdd = (number % 2 == 0) ? "EVEN" : "ODD";
String timeOfDay = (hours < 12) ? "A.M." : "P.M";
double taxRate = (income > 40000) ? 0.25 : 0.15;
}
}

BroCodez
Автор

Still one of the best beginner programming channels on youtube

ramble
Автор

thx a lot bro for teaching us the ternary operator in java. great series. keep up the good work 🔥

useronetwothree-zf
Автор

are they exchangeable or depends on situation?

lingodata
visit shbcf.ru