hacker.org Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
Valid java code

 
Reply to topic    hacker.org Forum Index » Wormageddon View previous topic
View next topic
Valid java code
Author Message
wicherh



Joined: 19 Dec 2008
Posts: 3

Post Valid java code Reply with quote
This is a pretty stupid question but a equation example: (1 = 1) returns 1 or 0 right so why would this not work?:
Code:
int right = dir + 1 - 4(dir = 4);
int left = dir - 1 + 4(dir = 0);

This code calculates right and left dir so i can use after this the code:
Code:
public static int[][] offsets = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } };
int nx = x + offsets[dir][0];
int ny = y + offsets[dir][1];
int nxr = x + offsets[right][0];
int nyr = y + offsets[right][1];
int nxl = x + offsets[left][0];
int nyl = y + offsets[left][1];


if I use the first code, it says [code]";" expected[code]
why does he ask that
Fri Dec 19, 2008 9:39 pm View user's profile Send private message
tog



Joined: 14 Nov 2008
Posts: 70
Location: Germany

Post Reply with quote
= is assignment
== is comparison
It's really a bad idea to assign to a variable which is used in the same statement again. You can never know which part of the statement is executed first.
But you actually wanna use modulo (%) for this task.
Fri Dec 19, 2008 10:31 pm View user's profile Send private message
brazzy



Joined: 07 Nov 2008
Posts: 14
Location: Munich, Germany

Post Re: Valid java code Reply with quote
wicherh wrote:
This is a pretty stupid question but a equation example: (1 = 1) returns 1 or 0 right so why would this not work?:
Code:
int right = dir + 1 - 4(dir = 4);
int left = dir - 1 + 4(dir = 0);

Not sure what that code is supposed to do, but it's definitely invalid as long as there is no operator in front of the parentheses. Also, what tog said.
Fri Dec 19, 2008 11:53 pm View user's profile Send private message Visit poster's website
wicherh



Joined: 19 Dec 2008
Posts: 3

Post Reply with quote
Yea got right code now with modulo.
If you are at a if statement there stays example
Code:
if (x = 1)
{
}


X =1 returns a value boolean true or false, 1 or 0.
int right = dir + 1 - 4(dir = 4); means:

int right = dir + 1 - 4 * (if dir = 4(if = true it returns a 1 value)) then the equanation does it -3
Sat Dec 20, 2008 10:22 am View user's profile Send private message
Display posts from previous:    
Reply to topic    hacker.org Forum Index » Wormageddon All times are GMT
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.