In: Computer Science
int a = 3; int b = -2; if((a>0)&&(b>0)){ if (a>b) { System.out.println("A"); } else { System.out.println("B"); } } else if ((b<0)||(a<0)) { System.out.println("C"); } else { System.out.println("D"); }
If the above program is executed in java then value of variable "a" is 3 and value of variable "b" is -2
By using braching statement(if .. else statement) a> 0 and b > 0 , here logical and operator is used if the bothe condition is true then it will execute if part otherwise it will execute else part .
In First nested if part it check a>b it print A
else it print B
In second else part (b<0) || (a<0) it print "C " and actually this condition is true , because here logical or operator is used , here if one condition is true it will execute i, e value of b = -2 and it true because it check b< 0 and value of a is 3 it check a<0 it is false , hence according to logical or if one codition is true operation will perform .
Otherwie in last else part it will print "D"
Code :
public class First
{
public static void main(String []args)
{
int a = 3;
int b = -2;
if((a>0)&&(b>0))
{
if (a>b)
{
System.out.println("A");
} else
{
System.out.println("B");
}
}
else if ((b<0)||(a<0))
{
System.out.println("C");
}
else
{
System.out.println("D");
}
}
}
Output:
C
Code (SS)
Output(SS):