0
What will be the code of this question?
During your math class, you are given a task to calculate the perimeter of a circle. You decide to write a small program that will take the radius as input, and will calculate and print the perimeter for you. The value for π (pi) is already defined. Sample Input 4 Sample Output 25.12
8 Antworten
+ 1
Hi! you've written a lot of your own code. re-write the program. your code should take three lines:
1. create a variable where the radius value will be taken.
2. create a second variable (perimeter). in this variable, write the correct formula for calculating the perimeter, where you will substitute the radius value. your first variable.
3. Display the perimeter variable on the screen.
Do not print anything superfluous in your program! and do not display unnecessary messages on the screen! your program should be concise.
+ 1
Thank u soo much.....
0
Show us your code attempt
0
you have to code the formula for the perimeter of a circle, please show us your attemps so we can help you out
0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double pi = 3.14;
System.out.println("Please enter radius of circle:");
float radius = scanner.nextFloat();
double perimeter = perimeter(radius);
System.out.println("Perimeter of Circle calculate by Java program is : "
+ perimeter);
scanner.close();
}
/*
* @return perimeter of a circle.
*/
public static double perimeter(float radius){
return 2*Math.PI*radius;
//your code goes here
}
}
0
Ok let me try it
0
all right, but just out of great respect for you, I'll allow it
0
Yes it worked