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

1. 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. 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.

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

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

UniverseCloud (February 7th, 2018)

6. Re: Help the newbie

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. 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