#14 Ternary Operator in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

For More Queries WhatsApp or Call on : +919008963671

Udemy Courses:

In this lecture we are discussing:
1)What is ternary operator?
2)Why do we need ternary operator?
3)Syntax of ternary operator
4)example of ternary operator

#1
-- ternary operator is shorthand of if-else statement.

#2
why we need ternary operator?
a) to reduce the code
b) to make the code more readable
c) to make the code more compact

#3
Syntax:
variable = (condition)?value1 if condition is true :value2 if condition is false
boolean result =(5 less then 6)? true :false; //result false

#4
example:
in if-else we can check a given number is even or odd now we code this problem by
ternary operator.

int num=13;
String str=(num%2==0)?"Even":"Odd";

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

Tulusko is the best online Tutor I have met.

cehost-tech
Автор

I had forgotten what it was, thanks for clearing it once again😂🙌🏻🙌🏻☺❤❣️

agnidhbhattacharya
Автор

2:26 comment out = ctrl + k then ctrl + c
To undo = ctrl + k then ctrl + u

nazsar
Автор

Ternary ki return value Boolean aaya gi

lbjzmlt
Автор

if we just keep the "result =0" as just "result", will it work the same?although i have tried but i am unsure about other examples, i mean there must be some reason to initialize it to "zero" right???

relaxationvideosbyteamrela
Автор

Can we ternary operator in if else statements..?

shaikmansoor
Автор

if i write System.out.println(10<20? 1:'A');
I am getting the output of some emojis why is that.

kalki
Автор

Why initialising result=0 first??

And why n%2==0 why equal to zero. We are just checking if its even or odd?

Anyone clarify.

Breakingbadtwd
Автор

how to use else if in ternary operator

LetsGOSam-kv