Sunday, July 30, 2023

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 ".

 




Week 1: Programming Assignment 1


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 ".




Program :


import java.util.Scanner;  

public class Exercise1_1 {

       public static void main(String[] args) {

Scanner s = new Scanner(System.in); 

       double radius= s.nextDouble();

       double perimeter;

       double area;


//Calculate the perimeter 

  //Calculate the area

if(radius<=0)

{

 System.out.println("please enter non zero positive number ");

}

else

{

 perimeter = 2 * Math.PI * radius;

area = Math.PI * radius * radius;

System.out.println(perimeter);

 System.out.print(area);

}

}

}




No comments:

Post a Comment