Identifying syntax and logical errors

Hey guys,

I'm new to java and I can't figure out this problem as I can't make JDK work with comand prompt for some reason and when trying to write the java in a web page it won't work.

Can anyone tell me what the three syntax errors and one logical error in the following code is?

public class Add

{

public static void main(String[] args)

{

double weight1 = 85.5

double weight2 = 92.3

double averWeight = weight1 + weight2 / 2;

System.out.println("Average is " + aver);

}

}

Any help would be very much appreciated.

[604 byte] By [Kaisa] at [2007-11-26 20:43:04]
# 1
Two of themdouble weight1 = 85.5;double weight2 = 92.3;
sabre150a at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 2
What should they be instead?
Kaisa at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 3
Plus a logical errordouble averWeight = (weight1 + weight2) / 2;Division binds more tightly than addition so in your version you would get weigh1 + half of weight2.
sabre150a at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 4
sorry... didn't notice ya semicolons.
Kaisa at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 5
> What should they be instead?Compare you statements with mine. See any difference?
sabre150a at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 6
Yeah, i just noticed the semicolons just after I posted. Apologies.
Kaisa at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 7
Should it beSystem.out.println("Average is " + averWeight);with averWeight instead of just aver?
Kaisa at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 8

> Should it be

>

> System.out.println("Average is " + averWeight);

>

> with averWeight instead of just aver?

What do you think? Do you see a variable named 'aver' declared

somewhere? I don't. And the compiler will nag at you for it.

kind regards,

Jos

JosAHa at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 9
Ok. I'm new to Java. Thanks to the both of you for your help.Michael.
Kaisa at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...
# 10

> Ok. I'm new to Java. Thanks to the both of you for your help.

You're welcome of course; here's a tip: type in these little exercises

and try to compile them; carefully read what the compiler has to say

about the possible errors. Note that the compiler is totally blind to

most "logical errors".

kind regards,

Jos

JosAHa at 2007-7-10 2:03:13 > top of Java-index,Java Essentials,Java Programming...