Average In Java - any help would be greatful
807599Feb 11 2007 — edited Feb 11 2007Hello, 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