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]
# 1
> 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?
prometheuzza at 2007-7-12 19:00:57 > top of Java-index,Java Essentials,Java Programming...
# 2
> > i have the following code , i wanna know it's> output and why Did you come to know the answer of your question ?
JL.Nayaka at 2007-7-12 19:00:57 > top of Java-index,Java Essentials,Java Programming...
# 3
You'll learn the leason much better if you spot it for yourself.
malcolmmca at 2007-7-12 19:00:57 > top of Java-index,Java Essentials,Java Programming...
# 4

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");

Pawcika at 2007-7-12 19:00:57 > top of Java-index,Java Essentials,Java Programming...