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

Thread: SUPER SIMPLE QUESTION!!!

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default SUPER SIMPLE QUESTION!!!

    I just started me java class and im confused about how powers work, such as

    Volume of Cylinder = PIE (radius)2(SUPPOSED TO BE SQUARE, NOT 2) *height


    how does the above translate to java code? specificly the power of 2, sry im stupid, thx


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: SUPER SIMPLE QUESTION!!!

    For exponents you use:
    Math.pow(A, B); //A is the original number. B is to what power

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: SUPER SIMPLE QUESTION!!!

    Take a look at the Java Platform SE 6 class. Most notably the pow method.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: SUPER SIMPLE QUESTION!!!

    I always write squares out (in my mind this is faster and more accurate, but not by much)

    Mmm, PIE. It's actually PI, and you can use Math.PI for the floating point representation of this number. Also, in Java you must explicitly spell out everywhere you're performing a multiplication/add/etc.

    double a = 3;
    double b = 3a; // error
    double b = 3 a; // error
    double b = 3 * a; // correct

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SUPER SIMPLE QUESTION!!!

    Volume of Cylinder = PI(radius)2(power 2) * height
    Surface Area of Cylinder = 2 PI radius * height

    ok so im confused on why my teacher would give me the above as a formulas. at my level of math and java programming the above makes no sense.. i can decipher the top one. but 2 pi radius * height.. umm wtf

    so its 2 * pi * radius * height? Why have one multiplication symbol and not the rest?

  6. #6
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: SUPER SIMPLE QUESTION!!!

    Your anwser should look like this

    int height = 2;
    int radius = 3;
    double volume = Math.PI * (Math.pow(radius, 2) )* height;
    Last edited by Brt93yoda; September 2nd, 2010 at 09:21 PM.

  7. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SUPER SIMPLE QUESTION!!!

    It isn't in parenthesis.. look at volume. o well, i got it fiqured out, i think my teachers kind of mean tho. THanks for the help everyone.

  8. #8
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: SUPER SIMPLE QUESTION!!!

    Did you see my above post?

Similar Threads

  1. [SOLVED] "possible loss of precision", except not, code doesn't work, simple question
    By Perd1t1on in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 07:11 PM
  2. Super Mario Frustration
    By Bryan in forum The Cafe
    Replies: 2
    Last Post: June 11th, 2010, 02:46 PM
  3. Simple Input Dialog Question
    By tabutcher in forum Java Theory & Questions
    Replies: 0
    Last Post: March 1st, 2010, 11:10 PM
  4. simple question...
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 2nd, 2010, 07:29 AM
  5. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM