0% found this document useful (0 votes)
4 views2 pages

Internet of Things

Iot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Internet of Things

Iot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

*Q4

*import java.util.Scanner;

class InvalidInputException extends Exception {

public InvalidInputException(String message) {

super(message);

public class CircleCalculator {

public static void calculateCircle() {

Scanner scanner = new Scanner(System.in);

while (true) {

try {

System.out.print("Enter the radius of the circle (between 1 and 20): ");

double radius = scanner.nextDouble();

if (radius < 1 || radius > 20) {

throw new InvalidInputException("Invalid input! Radius must be between 1 and 20.");

double area = Math.PI * radius * radius;

double circumference = 2 * Math.PI * radius;

System.out.println("Area of the circle: " + area);

System.out.println("Circumference of the circle: " + circumference);

break; // Break the loop if valid input is provided

} catch (InvalidInputException e) {
System.out.println(e.getMessage());

} catch (Exception e) {

System.out.println("Invalid input! Please enter a valid number.");

scanner.nextLine(); // Clear the input buffer

scanner.close();

public static void main(String[] args) {

calculateCircle();

You might also like