#3.1 Java Tutorial | If Else | Selection Statement

preview_player
Показать описание
In this lecture we are discussing:
1)Conditional Statements
2)Use of if (check single statements)
3)Use of if and else (for checking complementary condition)
4)Use of if , else if and else (more than two condition)
5)Use of curly braces is required or not

#1
Conditional Statements: If we say about conditional statements it means we have checking
condition and basis of this condition decide whether statement execute next line of code or not.

e.g check n=5 is even or odd
for checking such kind of condition we required conditional statements

we have three conditional statements:
a) if, else and else if
b)ternary operator
c)switch

Note: in this section we are only discussing about if and else statements.

#2
Use of if (Single condition)

e.g
check n is odd
for that we use if() statement
if(n%2!=0)

e.g
check n is equal to zero
if(n==0)

#3
Use of if and else

e.g
if you want to check complimentary condition
check n is even or odd
if(n%2==0)
else

e.g
check n is equal to zero or not
if(n!=0)
else

#4
use if, else if and else
if you want to check multiple condition

e.g
check whether number is zero , less than zero or greater than zero
if(n==0)
else if(n grater-then 0)
else

#5
Use of curly braces required or not

case 1:
Suppose after if, else if or else we have single statement then
we do not require braces but you can use
e.g
if(n%2==0)

if(n%2==0)
{
}

case 2:
if we have more than one statement after if , else if or else
we need to put curly braces
Correct way:

if(n%2==0)
{int a=5;
int b=6;
}

Incorrect way:
if(n%2==0)
int a=5;
int b=6;

Note: in such cases either you get error or you get unexpected answer

Recommended:
Always use curly braces either you have one statement or multiple statements;

More Learning :

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

Hello @Telusko Learning - as mentioned in video 2.5 that next video is on bitwise operator but same is missing. Also the same for the Relational Operators and Logical operators.

svishal
Автор

These videos are great for someone who already knows another language, thank you! Other tutorials are way too slow for me. Keep it up!

rmital
Автор

Naveen reddy garu u r really teaching awesome sir...

rohitsarat
Автор

Though these are known things ur presentation is perfect to glance, n to clarify each small confusions. I feel wow after watching every videos❤ thank you

johnhenry
Автор

You are amazing sir....
Thank you so much for your video

JitendraYadav-tsch
Автор

@Telusko please upload for bitwise, relational and logical operators plz i liked you explination thanks Naveen

abdifitahmashquul
Автор

Sir.. what about the Bitwise, Relational, and Logical operators... ? can you please share that video.?

chintu
Автор

ur's explanation is simply awesome and also am requesting please do the video on core Java interview questions at least monthly once....tq s a lot...guruji

nvharinadh
Автор

sir where is the video about bitwise operators?

nibinmathew
Автор

Are u creating new java playlist. What will be difference. ? Which one should we follow now

tejagemidi
Автор

Hello Navin, which selection statement we can use inside a for loop if we have to do three comparisons?, i have tested with "else if" multiple times but it is not giving the expected o/p. please suggest something. Thanks.

ankitshrivastava
Автор

Sir, i want to enter number in output..
I don't want to change input again and again (like putting5, putting4 and run)
I want my output like..
"Enter a number"
And then answer like... Even or odd

priyankareddygudupally
Автор

please add captions. I really cannot understand anything

grantwalter
Автор

The birds in Florida like to sing during favorable temperatures.
In particular, they sing if the temperature is between 60 and 90 (inclusive).
Unless it is summer, then the upper limit is 100 instead of 90.
Given an int temperature and a boolean isSummer,
return true if the birds are singing and false






class Floridabirdssinging
{
public static void main(String args[])
{
System.out.println(birdsSinging(true, 90));
System.out.println(birdsSinging(false, 120)); ////false
System.out.println(birdsSinging(false, 86)); ///true
System.out.println(birdsSinging(true, 96)); ///false

}
static boolean birdsSinging(boolean summer, int temp)
{
if(summer && ((temp > 60)||(temp<100)))
{
return true;
}
else if(summer && temp>100)
{
return false;
}
else if(summer=false && ((temp>60)||(temp<90)))
{
return true;
}
else if(summer=false && temp>90)
{
return false;
}
else
{
return false;
}
}
}

shabanakhanpathan
Автор

Sir please do for iterative statements

revengerlord
Автор

Sir which is the best computer book only for programming for class 9 & 10 icse ??

sankhadeepmondal
Автор

Also Can we write condition in else block ??

onlineyash
Автор

its printing both odd and even plz help

ramkarank
Автор

hi i have a question please reply me back .i need to know the mistake i have done

shabanakhanpathan
Автор

in python you tought how to put user input so early(which is good) but why not here!? without user input it's boring! and by the way 0 is an even number cuz 0/2==0, or remainder is 0, so 0 is even.

chaitanyasingh