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.
Re: Writing a JAVA Program for Calculating the Circumference of a Circle from a radiu
http://www.vbforums.com/ 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 ;
}
}
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!
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
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??
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?