| View previous topic :: View next topic |
| Author |
Message |
Jamestomo How do I cheat?
Reputation: 0
Joined: 14 Mar 2007 Posts: 7
|
Posted: Tue Oct 21, 2008 7:52 am Post subject: Divisible statements. |
|
|
hi, i'm quite new to java programming and have a question 'x equal to y and z is not divisible by 2.
I know the first bit is: if((x==y&&
but i'm not too sure how to add the 'z is not divisible by 2' part, can someone help me please?
Last edited by Jamestomo on Tue Oct 21, 2008 7:53 am; edited 1 time in total |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Oct 21, 2008 7:53 am Post subject: |
|
|
% == 0
Now gtfo and do your assignment yourself
|
|
| Back to top |
|
 |
SilentStorm Cheater
Reputation: 0
Joined: 01 Oct 2008 Posts: 27
|
Posted: Tue Oct 21, 2008 2:00 pm Post subject: |
|
|
Actually, a more efficient way would be just to test bit 0:
| Code: | if( (x==y) && !((z & 1)==0) )
{
} |
Of course, in the days of the 4 GHz multi-core processors, efficiency is a dying art, I know.
Edit: The above is C. Translate boolean and logical operators to Java if necessary. Also, an operation could be removed to make it even more efficient by propagating the 'not' operation [i.e., (z&1) != 0], but I leave it in for the sake of clarity.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Oct 21, 2008 2:29 pm Post subject: |
|
|
| SilentStorm wrote: |
Actually, a more efficient way would be just to test bit 0:
| Code: | if( (x==y) && !((z & 1)==0) )
{
} |
Of course, in the days of the 4 GHz multi-core processors, efficiency is a dying art, I know.
Edit: The above is C. Translate boolean and logical operators to Java if necessary. Also, an operation could be removed to make it even more efficient by propagating the 'not' operation [i.e., (z&1) != 0], but I leave it in for the sake of clarity. |
Screw efficiency, we're doing java here. If he gave that in it'd be obvious he didn't do it himself.
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Tue Oct 21, 2008 2:45 pm Post subject: |
|
|
Atleast he's not asking us to do it all.
To expand: the modulus (%) operator will give you the remainder of a division.
10%3 would be 1
_________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Oct 21, 2008 3:46 pm Post subject: |
|
|
| HalfPrime wrote: | Atleast he's not asking us to do it all.
To expand: the modulus (%) operator will give you the remainder of a division.
10%3 would be 1 |
No, he asked me.
|
|
| Back to top |
|
 |
|