Results 1 to 4 of 4
  1. #1
    TravisDavis is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Average of 3 numbers

    so i have to create a program that calculates the average of any 3 numbers and i keep running into the same error

    Java Code:
    /**
     * AWT Sample application
     *
     * @author 
     * @version 1.00 12/10/01
     */
    public class Project {
    	//---------------------------------------------------------
    	//  Read 3 integers and print the average
    	//---------------------------------------------------------
        public static void main(String[] args) {
        	
        	 int num1, num2, num3; // (num1+num2+num3)/3
        	 System.out.println ("Enter A Number:");
        	 num1 = keyboard.readInt();
        	 System.out.println ("Enter Another Number:");
        	 num2 = keyboard.readInt();
        	 System.out.println ("Enter One More Number:");
        	 num3 = keyboard.readInt();
        	 double Average;
        	 	Average = (num1+num2+num3) / 3.0;
        	 System.out.println ([B]"[/B]The Average Is:" = (Average) +":");
            
        }
    }
    Last edited by pbrockway2; 10-02-2012 at 01:47 AM. Reason: code tags added

  2. #2
    CODinacup is offline Member
    Join Date
    Sep 2012
    Posts
    13
    Rep Power
    0

    Default Re: Average of 3 numbers

    Your last line is wrong. Variables do not go in quotes, here is a revised last line.

    Java Code:
    System.out.println ("The Average Is:"+Average);

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Average of 3 numbers

    Hi TravisDavis, welcome to the forums!

    A couple of things. First when you post code use the "code" tags. Rather unintuitively the button for that is labelled #. (Run your mouse pointer along the various buttons and a popup will appear describing what each one does: going from bold/italic/underline on the left to programming language formatting on the right hand end). Alternatively you can enter the code tags yourself by typing [code] at the start of the code and [/code] at the end. The idea is to make the code readable when it appears on a we page.

    i keep running into the same error
    That's the second thing ... so, what is the error? If you have a compiler message that you can't understand copy and post the entire message as well as saying what lines of your code it is referring to.

    Now you might be thinking "I bet these people have seen this error - or something like it - before, so I needn't spell it out. Or they can throw the code at their own compiler and see the message for themselves." And you might be right. But programmers are lazy people and, more importantly, I would guess that all have learnt through their own hard won experience that the way to begin to solve problems is to describe them precisely and comprehensively.

    It's tedious, but effective. And, from HelloWorld onwards, necessary because you never stop having problems and, therefore, always face the need to describe them to others.

    Sorry, I ranted a bit... To repeat the substantive point: what is the compiler's message.

  4. #4
    TravisDavis is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Smile Re: Average of 3 numbers

    Quote Originally Posted by CODinacup View Post
    Your last line is wrong. Variables do not go in quotes, here is a revised last line.

    Java Code:
    System.out.println ("The Average Is:"+Average);

    thank you for this i found out what was wrong and this was actually part of it, so thank you for the help :)

Similar Threads

  1. how to change numbers into word numbers?
    By akeni in forum New To Java
    Replies: 13
    Last Post: 11-18-2011, 08:46 AM
  2. Replies: 11
    Last Post: 01-14-2011, 06:36 PM
  3. average
    By anjigadu in forum New To Java
    Replies: 4
    Last Post: 09-19-2010, 09:52 PM
  4. Need help getting average
    By soccer_kid_6 in forum New To Java
    Replies: 15
    Last Post: 09-12-2010, 11:59 PM
  5. printing two smallest numbers from a series of numbers
    By trofyscarz in forum New To Java
    Replies: 2
    Last Post: 10-14-2008, 11:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •