Sunday, December 5, 2010

How to use if statements in Java??

"If statements" could be used in java in the way as:
int b,a;;
if(b= = a)
{
//do here some thing
}
else
if(b>a)
{
a=0;
}
else
{
b=0;
}
Above program is in main function it will operate as two integer will be checked first of all(assign both of them any value i did'nt else program will not run) if both are equal do nothing(you can customize if body and force it to do anything). Then it will check int b whether its larger than int a or not if yes then it will assign int a=0 in the if body. If both of first two conditions failed then it will enter in else statment and assign int b=0(knowing that if int b is not larger or neither equal to it then int a must be larger than int b)

No comments:

Post a Comment