Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Thread: Finding the average of two double digits.

1. 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

```   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

2. Re: Finding the average of two double digits.

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

`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.

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).

3. The Following User Says Thank You to pbrockway2 For This Useful Post:

shifat96 (February 9th, 2012)

thanks!
+rep

5. Re: Finding the average of two double digits.

You're welcome.