Question

Java

Write a program that prompt the user to enter a decimal number representing the radius of a circle. If the number is greater or equal to zero, the program displays the area of the circle. Otherwise, the program displays “negative input”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CircleAreaDemo.java

import java.util.Scanner;

public class CircleAreaDemo {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the radius of a circle: ");

double radius = scan.nextDouble();

if(radius>=0) {

double area = Math.PI * radius * radius;

System.out.println("Circle Area: "+area);

} else {

System.out.println("negative input");

}

}

}

Output:

Enter the radius of a circle:
8
Circle Area: 201.06192982974676

Enter the radius of a circle:
-1
negative input

Add a comment
Know the answer?
Add Answer to:
Java Write a program that prompt the user to enter a decimal number representing the radius...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT