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

Thread: Help the newbie

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Help the newbie

    package com.company;

    public class Main {

    public static void main(String[] args) {

    double a = (1/84);
    double b = Math.sqrt(123456879);
    double c = Math.cbrt(2);
    double d = Math.PI(Math.sqrt(7));

    System.out.printf("%5.6f%n", a);
    System.out.printf("%5.6f%n", b);
    System.out.printf("%5.6f", c);

    }
    }

    Hey guys, the code above is for few questions i am solving, i am still a newbie at this and would like some help!

    Question 1: For "double a = 1/84" should be giving me an actual value but all i am getting is 0.000000, any thoughts ?

    Question 2: The square root of 123456789 is 11111.1110606 but in the java program it says 11111.115111, anyway to get a more accurate result ?

    Question 3: I need to calculate PI to the power of 7 so i tried Math.PI(Math.sqrt(7)); but it's giving me an error saying "Method call expected" But when i add the multiplication sign between mathPI and mathSQRT "Math.PI*(Math.sqrt(7));" it gives me a different answer than what i wanted.

    Thank you guys ^^

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Help the newbie

    Use a floating point value in the division. Integer division: 1/2 gives 0, floating point: 1.0/2 - 0.5

    anyway to get a more accurate result ?
    Look at using the BigDecimal class.

    it's giving me an error
    Please copy the full text of the error message and paste it here. It has important info about the error.

    gives me a different answer than what i wanted
    Please explain. Post the output to show what you are talking about and show what you want.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2017
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help the newbie

    Please copy the full text of the error message and paste it here. It has important info about the error.
    It just says Method call expected with this error

    Error10, 24) java: cannot find symbol
    symbol: method PI(double)
    location: class java.lang.Math

    Please explain. Post the output to show what you are talking about and show what you want.
    PI to the power of 7 should give me 3020.29322778 but i am getting 8.311873

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Help the newbie

    Error10, 24) java: cannot find symbol
    symbol: method PI(double)
    Read the API doc for the Math class. It does not have a method named PI. It has a static field named PI.
    http://docs.oracle.com/javase/8/docs/api/index.html

    PI to the power of 7 should give me 3020.29322778 but i am getting 8.311873
    Please post the code that gives that result.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    UniverseCloud (February 7th, 2018)

  6. #5
    Junior Member
    Join Date
    Aug 2017
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help the newbie

    Sorry for the late reply!

    Please post the code that gives that result.
    double d = Math.PI*(Math.sqrt(7));
    System.out.printf("%5.6f", d);

    P.S if i removed the multiplication sign and used "double d = Math.PI(Math.sqrt(7));" i'll be getting that error i showed you.

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Help the newbie

    PI to the power of 7
    double d = Math.PI*(Math.sqrt(7));
    Look at using the Math class's pow method for that, not the sqrt method.

    Note: The extra ()s around (Math.sqrt(7)) are not needed. Math.sqrt(7) will do
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Another newbie. Hi!
    By Conky2000 in forum Member Introductions
    Replies: 1
    Last Post: December 31st, 2012, 08:22 AM
  2. I'm a newbie
    By chanukya4528 in forum Member Introductions
    Replies: 0
    Last Post: July 5th, 2012, 10:04 AM
  3. Yo :D Newbie here =)
    By Sjogern in forum Member Introductions
    Replies: 4
    Last Post: February 21st, 2012, 11:15 AM
  4. Newbie
    By gavlaa in forum Member Introductions
    Replies: 1
    Last Post: May 24th, 2011, 07:00 AM
  5. Me = Newbie;
    By Bacon n' Logic in forum Member Introductions
    Replies: 6
    Last Post: August 31st, 2010, 08:28 PM