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.
Thanks in advance.
Shifat Taushif
shifat.tk
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
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).
Re: Finding the average of two double digits.
Re: Finding the average of two double digits.