Ahem!
Given only radius gives you all the other data. No need to input.
Circumference = 2 * PI * r
Area = PI * r * r
etc.
I'm also assuming your x is entered as a Floating-Point value.
System.out.printf("Area is %f\n", (x * x * math.PI) );
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
And also post what error you are getting. If you are successfully reading in the radius, then 2 * radius should give you the diameter without problems as long as the radius is declared as the correct type (i.e. float or double).
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Post your entire code! Errors can be misleading without seeing everything in context!
For example if x is an integer or a double it can cause a problem with that printf. The fact that it was multiplied with a float (PI) would make the result a float.
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
Because x is assigned from an input.nextInt(), I assume it's declared as int, so:
%f requires a floating point value, but 2*x is an integer value. Change the format to %d when you print the diameter, OR change the calculation to 2.0*x so the result is floating point.
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
x is an int. When you do a calc with just integers, the result is an int, but if it's mixed ints and floats, the result is float. Pi is a float. Area and circ. involved Pi, bit diameter didn't.
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073