Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,817 answers

573 users

How to calculate a circle perimeter in Java

2 Answers

0 votes
package javaapplication1;

public class JavaApplication1 {
  
    public static void main(String[] args) {
  
        int radius = 30; 
        
        double perimeter = 2 * Math.PI * radius;
               
        System.out.println("Perimeter of a circle is: " + perimeter);
    }
}
  
/*
run:
 
Perimeter of a circle is: 188.49555921538757
  
*/

 



answered Sep 18, 2016 by avibootz
0 votes
package javaapplication1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JavaApplication1 {
  
    public static void main(String[] args) throws IOException {
  
        int radius = 0; 
        System.out.print("Enter radius: ");
        
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            radius = Integer.parseInt(br.readLine());
        }
        catch(NumberFormatException ne)
        {
            System.out.println("Value Error: " + ne);
            System.exit(0);
        }
        catch(IOException ioe)
        {
            System.out.println("Error:" + ioe);
            System.exit(0);
        }
        
        double perimeter = 2 * Math.PI * radius;
               
        System.out.println("Perimeter of a circle is: " + perimeter);
    }
}
  
/*
run:
 
Enter radius: 45
Perimeter of a circle is: 282.7433388230814
  
*/

 



answered Sep 18, 2016 by avibootz
...