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 3 of 3

Thread: help

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default help

    // This program calculates the volume of a cone
    import java.io.*;
    class number14{
        public static void main(String a[]) throws IOException{
            System.out.println("This program calculates the volume of a cone");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter the radius of the cone: ");
            double r = Double.parseDouble(br.readLine());
     
            System.out.println("Enter the height of the cone");
            double h = Double.parseDouble(br.readLine());
     
            double v = (1/3) * (3.14) * (r * r) * h;
            System.out.println("The volume of the cone is "+ v);
     
        }
    }


    The volume always returns 0, for any value of r and h.What am i doing wrong?? help!!!
    Last edited by jps; August 17th, 2013 at 01:05 AM. Reason: code tags

  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: help

    Welcome studet
    Please use code tags when posting code, help can be found here

    (1/3) = 0 (integer division, not double division)
    zero times any number is zero

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

    studet (August 17th, 2013)

  4. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: help

    Thank you!!