Code to print perimeter of circle | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
- 1

Code to print perimeter of circle

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double pi = 3.14; //your code goes here int radius = scanner.nextint(); int per= 2*pi*radius; System.out.println(per); } }

10th Sep 2021, 8:55 AM
Phantom
4 Antworten
+ 1
Phantom No you can't convert double to int like that, you will get error. So cast with int like this: int per = (int) (2 * pi * radius); Btw in this practice result would be as double so assign calculation to a double variable.
10th Sep 2021, 9:53 AM
A͢J
A͢J - avatar
0
Is there a way to convert double into integer
10th Sep 2021, 9:06 AM
Phantom
0
Yes through typecasting
10th Sep 2021, 9:23 AM
Atul [Inactive]
0
Phantom make the per variable double
10th Sep 2021, 10:04 AM
Atul [Inactive]