if-else by if else we can test. like if taka=1 print "there is one taka" but if there is more taka then print "More taka" last one is worked by else.if if condition is false then print what else says.
example:
public static void main(String args[]){
int x=10,y=23,z=2,i=10;
if(x==i)
System.out.println("X and I is same ");
else
System.out.println("X and I is same ");
if(x>y)
System.out.println("X is greater than Y ");
else
System.out.println("X is not greater than Y ");
if(x<y)
System.out.println("X is less than Y ");
else
System.out.println("X is not less than y ");
if(x>=i)
System.out.println("X is greater than or equal I ");
else
System.out.println("X is not greater than or equal I");
if(x<=y)
System.out.println("X is less than Y ");
else
System.out.println("X is not less than Y");
if(y>x&&x>z)
System.out.println("Y is Maximum and Z is Minimum");
else
System.out.println("Y is not Maximum and Z is not Minimum");
if(y>x||z>x)
System.out.println("May be y is the Mximum number");
else
System.out.println("may be y is Minimum number");
}
}
output
X and I is same
X is not greater than Y
X is less than Y
X is greater than or equal I
X is less than Y
Y is Maximum and Z is Minimum
May be y is the Mximum number
here is our code.now see what happened
if(x==i)
System.out.println("X and I is same ");
else
System.out.println("X and I is same ");
here says if x is equal to i then print "X and I is same" but if it is false then print "X and I is same"
now see x=10 and i = 10 so they are equal. so print if condition.
if(x>y)
System.out.println("X is greater than Y ");
else
System.out.println("X is not greater than Y ");
here says if x greater than y then print " X is greater than Y " but if it is false then print "X is not greater than Y " now see x=10 and y= 23 so x is not greater then y. so if condition is false.so that here print else condition.
if(x<y)
System.out.println("X is less than Y ");
else
System.out.println("X is not less than y ");
here says if x less than y then print " X is less than Y " but if it is false then print "X is not less than Y " now see x=10 and y= 23 so x is less then y. so if condition is true.so that here print if condition.
if(x>=i)
System.out.println("X is greater than or equal I ");
else
System.out.println("X is not greater than or equal I");
here says if x greater than or equal i then print " X is greater than or equal I " but if it is false then print " X is not greater than or equal I " now see x=10 and i= 10 so x is equal i. so if condition is true.so that here print if condition.
if(x<=y)
System.out.println("X is less than Y ");
else
System.out.println("X is not less than Y");
here says if x less than or equal y then print " X is less than Y " but if it is false then print " X is not less than Y " now see x=10 and y= 23 so x is less than y. so if condition is true.so that here print if condition.
if(y>x&&x>z)
System.out.println("X is Maximum and Z is Minimum");
else
System.out.println("X is not Maximum and Z is not Minimum");
here says if y is greater than x and x is greater than z then print " X is Maximum and Z is Minimum " but if it is false then print " X is not Maximum and Z is not Minimum " now see x=10,y= 23,z=2 so y is greater than x and x is greater than z. so if condition is true.so that here print if condition.
(remember if and operator it is must to true both condition for if condition)
if(y>x||z>x)
System.out.println("May be y is the Mximum number");
else
System.out.println("may be y is Minimum number");
here says if y is greater than x or z is greater than x then print " May be y is the Mximum number " but if it is false then print " may be y is Minimum number " now see x=10,y= 23,z=2 so y is greater than x and z is not greater than x,but see here one condition is true. so if condition is true.so that here print if condition.
(remember if or operator it is not must to true both condition for if condition,if one condition is then also condition is true)
Here ends today. Best of luck
0 comments:
Post a Comment