I have been trying to build a Java program to prompt the user to enter the radius of a circle and the diameter, circumference, and area will be output through a "System.out.printf" statement. I can get the program to prompt for the radius and it will display the diameter, but will not identify the Area or Circumference. I keep getting an error with the Math variable. What could be wrong with this code for Area:
System.out.printf("Area is %d\n", (x * x * math.PI) );
NewToThis
0
Newbie Poster
Recommended Answers
Jump to PostAhem!
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 * …
Jump to PostPlease post your code!
Jump to PostAnd 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).
All 10 Replies
wildgoose
420
Practically a Posting Shark
NewToThis
0
Newbie Poster
wildgoose
420
Practically a Posting Shark
BestJewSinceJC
700
Posting Maven
NewToThis
0
Newbie Poster
wildgoose
420
Practically a Posting Shark
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NewToThis
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NewToThis
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.