Nptel 2020: Programming in java Week 1:Q1 Answer

Complete the code segment to find the perimeter and area of a circle given a value of radius.

You should use Math.PI constant in your program. If radius is zero or less than zero then print ” please enter non zero positive number “.

if(radius <= 0){
           System.out.print("please enter non zero positive number");
       }else{
           //Area of Circle
           area = Math.PI * radius * radius;
 
           //Perimeter of Circle
           perimeter = 2 * Math.PI * radius;
 
           //Print the Result
           System.out.println(perimeter);
           System.out.print(area);
}

Leave a Reply

Your email address will not be published. Required fields are marked *