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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Finding the average of two double digits.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    My Mood
    Depressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question 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.
    Thanks in advance.

    Shifat Taushif
    shifat.tk


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

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

  4. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    My Mood
    Depressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Finding the average of two double digits.

    thanks!
    +rep

  5. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Finding the average of two double digits.

    You're welcome.

Similar Threads

  1. All Digits only
    By kram in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 28th, 2011, 03:16 PM
  2. Replies: 20
    Last Post: June 26th, 2011, 05:40 PM
  3. Problem with digits/letters
    By te09hn8 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 22nd, 2011, 07:30 PM
  4. Finding the Average
    By KiwiFlan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2010, 07:58 PM
  5. Replies: 2
    Last Post: February 4th, 2009, 11:24 AM