# Finding the average of two double digits.

• February 9th, 2012, 04:45 PM
shifat96
Finding the average of two double digits.
Hello,
I have to do an assignment for school. I have to write a code for a program that calculates the average of to double numbers. I wrote this is NetBeans and it gives me the following errors:

the variables first and second may have not been initialized
cannot find symbol sc

Code :

``` public class DecimalAveShifat { public static void main(String args []){ double first; double second; double mean1; double meanf; mean1 = first + second; meanf = mean1 / 2; System.out.println ("First Decimal Number: "); first = sc.nextDouble (); System.out.println ("Second Decimal Number: "); second = sc.nextDouble (); System.out.println ("The avarage of the two is " + meanf) ; } }```

I am just a beginner. It has only been a week since I started computer science class at school.
If anyone could tell me what is wrong, and the fix for it, it would be wonderful.

Shifat Taushif
shifat.tk
• February 9th, 2012, 05:43 PM
pbrockway2
Re: Finding the average of two double digits.
Quote:

the variables first and second may have not been initialized
The compiler is telling you that you are trying to use first and second before you have given them any value.

Basically you cannot say

Code :

`mean1 = first + second;`

until after you have got the user input and assigned it to first and then second. So move that line down a bit.

Quote:

cannot find symbol sc
You get this message if you haven't declared a variable. In this case you forgot to say what sc is and assign it a value. (You will also see this message when you make a typo and type the wrong thing for a variable).
• February 9th, 2012, 05:47 PM
shifat96
Re: Finding the average of two double digits.
thanks!
+rep
• February 9th, 2012, 06:03 PM
pbrockway2
Re: Finding the average of two double digits.
You're welcome.