Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Average In Java - any help would be greatful

807599Feb 11 2007 — edited Feb 11 2007
Hello, I'm very new to Java programming and have started to build a program which works out the average of 3 numbers.

The code i have (and works fine) is:

public class Average
{
public static void main(String arg[])
{
int number1;
int number2;
int number3;
int average;
int sum;

number1 = 10;
number2 = 20;
number3 = 30;
sum = number1 + number2 + number3;
average = sum / 3;

System.out.println"Average: " + average);
}
}

This program works out the average no problems, however it isn't user friendly as it will always work out the average of 10,20 and 30. I would like to place an option for the user to choose the numbers so they can find out the average of 3 numbers. This however has completely thrown me and every attempt has failed.

Would anyone be able to point me in the direction of where i can find a tutorial of anything to aid me?

Many thanks for your help.

James
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 11 2007
Added on Feb 11 2007
10 comments
144 views