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: Not getting the correct output

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Not getting the correct output

    import java.util*;

    public class Ch3_Prexercise2
    {
    static Scanner console = new Scanner(System.in);

    public static void main(String[] args)
    {
    int height;
    int radius;

    double height;
    double radius;

    System.out.print(Enter the height of the cylinder: ");
    radius = console.nextDouble();
    System.out.println();

    System.out.print("Volume of the cylinder = "
    + PI * Math.pow(radius, 2.0 + height);

    System.out.print("Enter the radius of the base of the "
    + " cylinder: ");
    height = console.nextDouble();

    System.out.println();

    System.out.println("Surface area: "
    + (2 * PI * Math.pow(radius, 2.0))
    + (2 * PI * radius * height));
    static final double PI = 3.14159;
    }
    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Not getting the correct output

    Consider
    • Telling us what this program is supposed to do. We can't read minds and so have no idea what the "correct output" might be.
    • Telling us what this program currently does. Does it compile or are there compilation errors? Does it throw exceptions? If you receive any errors or exceptions, then post them.
    • Surround your code with [code=java] [/code] tags as per the forum FAQ. This helps your posted code retain its formatting so that it might be readable.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Not getting the correct output

    sorry.....
    the program needs to prompt the user to input the height and the radius of the base of a cylinder and output the volume and surface area of the cylinder. Also modify the relevant output statements to format the output to two decimal places

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Not getting the correct output

    And how is it not currently working? What is wrong with the above code? And again, can you edit your first post and place [code=java] [/code] tags around it:

    [code=java]
    //... your code goes here
    [/code]

Similar Threads

  1. how could I output to a text area the output of a method
    By mia_tech in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 12th, 2012, 08:49 PM
  2. [SOLVED] No errors, but output not correct? Only one loop performed correctly! Help please :)
    By coffecupcake in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 21st, 2012, 11:18 AM
  3. Is this correct? Tips if any please
    By giga97 in forum Object Oriented Programming
    Replies: 1
    Last Post: October 8th, 2011, 11:03 AM
  4. [SOLVED] Code is correct, but incorrect output?
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 6th, 2011, 02:32 PM
  5. Correct Coupling
    By poulenc in forum Java Theory & Questions
    Replies: 0
    Last Post: December 26th, 2010, 04:28 AM