0

Primitive operators

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 https://code.sololearn.com/ckpsyjMMHtmU/?ref=app

4th Jun 2021, 9:13 AM
Somvardhan Shiva
Somvardhan Shiva - avatar
12 Respuestas
+ 9
//try this import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double pi = 3.14; int radius = scanner.nextInt(); System.out.println(2*pi*radius); } }
4th Jun 2021, 12:34 PM
Simba
Simba - avatar
+ 8
Perimeter of a circle means circumference. C = 2πr You need to declare radius as an input variable instead of giving direct values. int radius=new Scanner(System.in).nextInt();
4th Jun 2021, 11:05 AM
Simba
Simba - avatar
+ 2
Formula is 3.14*radius*2 Change the last line to System.out.println(area);
4th Jun 2021, 10:43 AM
Atul [Inactive]
+ 2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double pi = 3.14; double r=scanner.nextInt(); //your code goes here double area=pi*r*r2 System.out.println (area); } } //Modified your code just check
4th Jun 2021, 11:35 AM
Atul [Inactive]
+ 1
import java. util.*; public class Program { public static void main(String[] args) { int radius=new Scanner(System.in).nextInt(); int area=3.14*radius*2; System.out.println (area) ; } } //Try this
4th Jun 2021, 10:57 AM
Atul [Inactive]
+ 1
Somvardhan Shiva sorry I thought that you are checking for area as you have made a variable area Formula is 2*3.14*r
4th Jun 2021, 12:48 PM
Atul [Inactive]
0
Ask question only.
4th Jun 2021, 9:17 AM
lisa
0
Ok
4th Jun 2021, 9:29 AM
Somvardhan Shiva
Somvardhan Shiva - avatar
0
Ok, tell me what is the formula for finding the area of circle
4th Jun 2021, 9:38 AM
Atul [Inactive]
0
Scanner scanner = new Scanner(System.in); double pi = 3.14; int radius = 4; double area = 2*3.14*4; //your code goes here Systemy.out.println (area); } }
4th Jun 2021, 10:07 AM
Somvardhan Shiva
Somvardhan Shiva - avatar
0
Sorry guys its not working
4th Jun 2021, 11:33 AM
Somvardhan Shiva
Somvardhan Shiva - avatar
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double pi = 3.14; int radius = scanner.nextInt(); System.out.println(2*pi*radius); } } Good Luck
26th Jan 2022, 6:17 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar