i was testing the use of if and else statements in java and come across a really
awkward situation
my code
----------------------------------xxxxxxxxxxxxxxxxxx----------------------------\
-------------
public class gear
{
public static void main(String args[])
{
int i=0;
if (i=0)
{
System.out.println("zero");
}
else
{
System.out.println("test");
}
}
}
----------------------------------xxxxxxxxxxxxxxxxxx----------------------------\
-------------
whenever i compile the above program i get the compilation error : -
gear.java:6: incompatible types
found : int
required: boolean
if (i=0)
^
i changed the above code to : -
----------------------------------xxxxxxxxxxxxxxxxxx----------------------------\
-------------
public class gear
{
public static void main(String args[])
{
int i=0;
//changed the if statement to not equal to
if (i!=0)
{
System.out.println("zero");
}
else
{
System.out.println("test");
}
}
}
----------------------------------xxxxxxxxxxxxxxxxxx----------------------------\
-------------
it compiled without errors and displayed
test
I'm writing a program for handling numbers and cannot understand the mess.