Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need help" Watch "Need help" New topic
Author

Need help

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
class MyNewVector
{

public static void main(String[] args)
{
public void test(int x)
{
double odd = x%2;
if ((odd)
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
}
}

Gives the compliation errors
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
void is an invalid type for the variable test
Syntax error on token "(", ; expected
Syntax error on token ")", ; expected
Type mismatch: cannot convert from double to boolean

at foo.MyNewVector.main(MyNewVector.java:9)
Can some one focus on this


Thanks<br />Dinesh
Prasun Howlader
Ranch Hand

Joined: Oct 21, 2007
Posts: 89
if ((odd)
{
System.out.println("odd");
}
else
{
System.out.println("even");
}

First you must finished parenthises )
Second for if condition compiler needs boolean expression but you use double.


"Control time instead of letting time control you."
Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
class MyNewVector
{

public static void main(String[] args)
{
public void test(int x)
{
double odd = x%2;
if (odd)
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
}
}

Now also it gives me error of boolean where i need to include boolean i can't understand.
Prasun Howlader
Ranch Hand

Joined: Oct 21, 2007
Posts: 89
boolean odd = true;
if ((odd))
{
System.out.println("odd");
}
else
{
System.out.println("even");
}

Now the program compile.
Alejandro Galvan
Ranch Hand

Joined: Jan 02, 2008
Posts: 48
Hi Dinesh:

Conditional and loop statements evaluates a boolean expression, but numeric, you can NOT, like in C or other languages, evaluate a condition with a number (false=0 or true!=0). So, you can NOT say:

You must use a boolean, or even a Boolean, which its only possible values are true or false, literally.
So, you do can say:


Hope this help you.


SCJP 5.0<br />Preparing SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help
 
Similar Threads
Error in using JWIG
problem in System.out.println
What is wrong with my code?
reference to method1 is ambiguous ..... java can't decide whic one to call.
processLine