+ 2
Can anyone help me with this Java coding?
Write a java program that print the circumference of a circle. The input of the program is diameter. Given that the diameter is 11.8. Display the result in three decimal places. (Note π = Math.PI)
4 Antworten
+ 5
Try to use format..
System.out.format ( "%.3f", c);
This will give you 3 decimal places.
Also nextInt() is used for taking integer inputs. for double, you should use nextDouble() method.
+ 4
Circumference of a circle = π * D ( D = diameter)
and for three decimal places you can use format.
+ 2
Below is my attempt but I don’t know how to display in 3 decimal places.
Scanner keyboard = new Scanner (System.in);
double d, c;
System.out.print("The diameter of circle = ");
d = keyboard.nextInt();
double r = d/2;
c = (Math.PI)*r*(2/1.0);
System.out.println(c);
+ 2
Alright, thank you! I just solved it!