|
-
Sep 17th, 2006, 02:15 AM
#1
Thread Starter
New Member
Writing a JAVA Program for Calculating the Circumference of a Circle from a radius
i found a similar query under the "C / C++" forum that was answered apparently using the "C" language. im in dire need of it in Java. i was wondering if someone could help me with it as i am having a hard time figuring out where to begin.
can anyone please show me how to write the java program taking into consideration the following conditions? :
1) must be a stand-alone application
2) calculation of circle's circumference must be from a radius which will be an integer value input from the keyboard.
3) create a method that will accept the integer and perform the calculation using the formula: "2*pi*r".
4) may use either the value "3.14" or the Java variable, "Math.PI" for the calculation.
i would really appreciate the help! thanks a bunch in advance!
PS - by the way, i use the Eclipse SDK compiler.
-
Sep 18th, 2006, 07:08 AM
#2
Re: Writing a JAVA Program for Calculating the Circumference of a Circle from a radiu
to the Forums
Try this:
Code:
public class MyClass
{
public static void main ( String args[] )
{
Scanner s = new Scanner( System.in ) ;
System.out.println( "Please enter the radius of the circle:" ) ;
int r = s.nextInt() ;
System.out.printf( "The circumference of the circle of radius %d is %f", r,
Circumference( r ) ) ;
}
private static double Circumference ( int radius )
{
return Math.PI * 2 * radius ;
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 19th, 2006, 09:55 PM
#3
Thread Starter
New Member
Re: Writing a JAVA Program for Calculating the Circumference of a Circle from a radius
yep, it did work. just changed the variables and added a few more. thanks a bunch!
thanks for the welcome greeting, too. cheers!
-
Sep 20th, 2006, 10:31 AM
#4
Re: Writing a JAVA Program for Calculating the Circumference of a Circle from a radius
You are welcome, don't forget to mark the Thread resolved from the "Thread Tools" menu
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 2nd, 2006, 01:00 AM
#5
New Member
Re: Writing a JAVA Program for Calculating the Circumference of a Circle from a radius
Wow...that program worked great. I was wondering if there was a way to do the same thing except also:
Write your own constructors, your own copy constructor, your own equals method. Include a method to prompt the user for the radius of a circle. And then Define your own toString() method. In your driver use the toString() method to test your constructor and to display the current radius after the user has entered a radius.
Any ideas??
-
Nov 2nd, 2006, 04:37 AM
#6
Re: Writing a JAVA Program for Calculating the Circumference of a Circle from a radius
???
Constructors? Copy constructors? (Never heard that term in relation to Java.) toString()?
What nonsensical assignment is that?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|