hi every body (new member ,mercy plz), boolean problem
i have the following code , i wanna know it's output and why
boolean bool =true;
if(bool =false){
System.out.println("a");
}elseif (bool){
System.out.println("b");
}elseif (!bool){
System.out.println("c");
}else{
System.out.println("d");
}
thanx all
bye
[952 byte] By [
marwa_mfa] at [2007-11-27 7:09:34]

> i have the following code , i wanna know it's output and why > ...Well, compile and run it.You do know the difference between the = and == operator, right?
Hi,
first you need to know is the difference between the binary operators: "=" and "==".
The "=" operator is an assignment operator and in fact it is a function that returns the value it assigned. The second operator "==" is an equality operator used to check references or primitive types. See comments inline:
> boolean bool = true;
> if(bool = false) { // this assignment sets bool to false and returns false so "a" will not be printed
>System.out.println("a"); // no printing
> } else if (bool) { // bool is false
>System.out.println("b"); // no printing
> } else if (!bool) { // bool is false so !bool is true, the condition is true
>System.out.println("c"); // printing "c"
> } else { //upper condition is true so no other else is executed
>System.out.println("d");