NPTEL_Programming In Java Week 1: Programming Assignment 1 August 2023


 

Week 1: Programming Assignment 1

Due on 2023-08-10, 23:59 IST

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

Your last recorded submission was on 2023-07-31, 09:34 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;  
2
public class Exercise1_1 {
3
       public static void main(String[] args) {
4
Scanner s = new Scanner(System.in); 
5
       double radius= s.nextDouble();
6
       double perimeter;
7
       double area;
8
//Calculate the perimeter 
9
  //Calculate the area
10
      
11
if (radius< 0.0)
12
  System.out.println(" please enter non zero positive number ");
13
else
14
{
15
  perimeter=2* Math.PI * radius;
16
  area= Math.PI*radius*radius;
17
  System.out.print(perimeter+ "\n" + area);
18
}
19
0
}
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   



InputOutput
Test Case 1
2.0
12.566370614359172
12.566370614359172

No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...