Java Help

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
Tasoth
Sith Devotee
Posts: 2815
Joined: 2002-12-31 02:30am
Location: Being Invisible, per SOP

Java Help

Post by Tasoth »

I've finished two of the three assignments for homework, but the last is a text book short answer essay. We're supposed to find the errors in the code, but I can't. Could someone help?

Code: Select all

int  number1;
int number2;
int result;

number1 = (4 * 6 - 4) / (10 % 4 - 2 );
number2 = ( 16 / 3) - 2 * 6+ 1;
result = number1 - number2;
my initial thought was division by zero, but I worked it out on paper and it seems fine.
I've committed the greatest sin, worse than anything done here today. I sold half my soul to the devil. -Ivan Isaac, the Half Souled Knight



Mecha Maniac
User avatar
Executor32
Jedi Council Member
Posts: 2088
Joined: 2004-01-31 03:48am
Location: In a Georgia courtroom, watching a spectacle unfold

Post by Executor32 »

I don't know whether these are the errors you had in mind, or simple mistypes while composing the post, but I see two instances of extra spaces and one of a missing space. There is an extra space before number1 in line 2, an extra space before 16 in line 7, and a missing space after the 6 in line 7.

So, if I'm not mistaken, it should read as this:

Code: Select all


int number1;
int number2;
int result;

number1 = (4 * 6 - 4) / (10 % 4 - 2 );
number2 = (16 / 3) - 2 * 6 + 1;
result = number1 - number2;
どうして?お前が夜に自身お触れるから。
Long ago in a distant land, I, Aku, the shape-shifting Master of Darkness, unleashed an unspeakable evil,
but a foolish samurai warrior wielding a magic sword stepped forth to oppose me. Before the final blow
was struck, I tore open a portal in time and flung him into the future, where my evil is law! Now, the fool
seeks to return to the past, and undo the future that is Aku...
-Aku, Master of Masters, Deliverer of Darkness, Shogun of Sorrow
User avatar
Crayz9000
Sith Apprentice
Posts: 7329
Joined: 2002-07-03 06:39pm
Location: Improbably superpositioned
Contact:

Post by Crayz9000 »

It's trivially easy to point out -- if you know the way that Java evaluates the order of operation.

Here's a hint: it's parenthesis, *, /, %, and then + and -.

Now re-evaluate the stuff and you'll see that there is a very blatant and obvious divide by zero error in there.
A Tribute to Stupidity: The Robert Scott Anderson Archive (currently offline)
John Hansen - Slightly Insane Bounty Hunter - ASVS Vets' Assoc. Class of 2000
HAB Cryptanalyst | WG - Intergalactic Alliance and Spoof Author | BotM | Cybertron | SCEF
User avatar
Tasoth
Sith Devotee
Posts: 2815
Joined: 2002-12-31 02:30am
Location: Being Invisible, per SOP

Post by Tasoth »

Thankee so much.
I've committed the greatest sin, worse than anything done here today. I sold half my soul to the devil. -Ivan Isaac, the Half Souled Knight



Mecha Maniac
Post Reply