Question
Jan Villaroel
Topic: Computer Science Posted 1 year ago
Write an application that inputs from the user the radius of a circle as an integer and prints the circle’s diameter, circumference and area using the floating-point value 3.14159 for π

Write an application that inputs from the user the radius of a circle as an integer and prints the circle’s diameter, circumference and area using the floating-point value 3.14159 for π. Use the following formulas (r is the radius): diameter = 2r circumference = 2πr area = πr2. Do not store the results of each calculation in a variable. Rather, specify each calculation as the value that will be output in a System.out.printf statement.


Answers
What are best answers and total votes?
No Votes
Vote
SignIn to Vote
Koala Tutor
Sep 4, 2023
Koala Ai Support

import java.util.Scanner;

public class CircleCalculations {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.print("Enter the radius of the circle: ");
int radius = sc.nextInt();

System.out.printf("Diameter: %.2f%n", 2 * (double) radius);
System.out.printf("Circumference: %.2f%n", 2 * 3.14159 * radius);
System.out.printf("Area: %.2f%n", 3.14159 * radius * radius);

sc.close();
}
}

Koala Tutor Got a question with my answer?
Message Me