Well, we have a plan. Let's implement it. First, implement a method that calculates the circumference of a circle. To do this, you need to write the correct formula in the method and specify the arguments. But what about pi, which we know is 3.141592... and so on to infinity? We'll keep things simple: let pi = 3.14.
Calculate the circumference of a circle
- 1
Locked
Comments (29)
- Popular
- New
- Old
You must be signed in to leave a comment
VandruGG Software Developer
28 September 2022, 21:26
The solution is simple. Have to create a variable to store the value of PI (this must be double type because PI is a floating number), then create a variable to use the formula. At the end, print the value of that variable on screen like all the past examples.
Radius value is obtained from main method that is passed as parameter.
+2
Anonymous #10829459
8 October 2021, 16:20
doble ...
doble ..
system c
+2
Anonymous #10793745
17 September 2021, 11:51
Can someone please clarify why you must use "int radius" for the method and why it won't work with a double? I would assume that it would be the exact opposite, the instructions even say that the result should be a fractional double.
0
Dav
23 October 2021, 14:36
I tried it on another compiler switching out double for int. It compiled fine.
Also, stackoverflow mentions it is default. “ By default, Java uses double to represent its floating-point numerals (so a literal 3.14 is typed double). ” and the reqs just say it will be a “fractional number” that happens to be a “(double)”.
+1
Sergio
30 December 2022, 07:07
Because radius is 5
0
MathBechy
2 July 2021, 15:10
I love it!!!
0
Shadow
2 April 2021, 18:17
I did not have to declare any variables for it to pass... But what I am wondering is how the answer came out as a double, when only the data type int was used?
0
Java_Mooood
12 October 2020, 20:00
declare 2 double variables in printCircleCircumference , pi and c
print the c , second variable
+2
Steven
24 November 2020, 21:12
awesome :)
0
Velociraptor
23 July 2020, 09:28
This is not working
the first condition is not satisfied
+3
byron
17 May 2020, 08:41
Where do you all explain the lesson?
+2
P S
26 April 2020, 14:09
I'm a little mixed up myself. I got the same thing you did, but for some reason, it's not accepting my code. When I say System.out.print(C), i get 31.400000000000002, but when I say System.out.print(pi), I get 3.14. Am I doing something wrong?
+1
P S
28 April 2020, 13:57
And its also not working when I change the 'pi' value to .314. Can someone please help me?
+1
Roman
29 April 2020, 07:27
Please refer to Help section at our course.
+1
lucascorrea Backend Developer at Compasso UOL
9 October 2021, 14:28
Hello, friend! You can use 'printf' instead of, thus, you can use decimal formatting like this:
The return will be with only two decimal places.
0
Felix
24 December 2019, 07:01
I know my code is all out of wack but this generated a correct answer. Can anyone concur?
+1