View Single Post
Old 02-07-2004, 12:50 AM   #1 (permalink)
ToolBag
Insane
 
Location: Chicago
[java] Question for an online lab.

Ok, I hope once I get help on this I will think to myself how simple this really is. But I am trying this online learning to teach myself java, and I have come to a question:

Write an expression that evaluates to true if the integer variable x contains an even value, and false if it contains an odd value

so I wrote:

if (x % 2 = 0) // check if its even
{
s = true;
}
else
{
s = false;
}

and this website gives me an error saying:

-Unexpected identifiers: false, s, true
-Just write an expression -- not a statement!
-There is no need for an assignment operator here (=).

ok, so this is simple feedback, but maybe I just missed the section on writing simple expressions or something but I cant find it. Also note, variable s was declared earlier in the program as a boolean. The website gives their code implemented with my incorrect code and it looks like this:

Our Code 1 public class CTest {
2
3 public static void main(String[] args) {
4
5 int x=5;
6 boolean s;
7
8 s=


Your Code: 9 if (x % 2 = 0)
10 {
11 s = true;
12 }
13 else
14 {
15 s = false;
16 }


Our Code 17
18 ;
19 }
20 }

any help would be greatly appreciated for there are 5 other questions I cannot answer because Im just not understanding what they really want when they say expression I guess. Thanks in advance.
__________________
Jesus was a ruffies victim!

Dan 3:20
ToolBag is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73