Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:27:10+00:00 2026-05-31T13:27:10+00:00

So my question is on this: This program is supposed to calculate the area

  • 0

So my question is on this:
This program is supposed to calculate the area of circle
the user inputs a number comes out with the answer
also any invalid input is not allowed i use the try-catch but it wont work…

Thank you so much for you time everyone :))

Here is the code:

import java.util.Scanner; 
import java.io;

/**
 *
 * @author Osugule
 */
public class AreaCircle { 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
Scanner sc = new Scanner(System.in); // read the keyboard
System.out.println("This program will calculate the area of a circle");
System.out.println("Enter radius:");//Print to screen
double r = sc.nextDouble(); // Read in the double from the keyboard
double area = (3.14 *r * r); 
try {

}
catch( NumberFormatException e ) {
    System.out.println("Invalid Input, please enter a number");
    //put a message or anything you want to tell the user that their input was weird.
}

String output = "Radius: " + r + "\n";
output = output + "Area: " + area + "\n";
System.out.println("The area of the circle  is " + area);

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:27:11+00:00Added an answer on May 31, 2026 at 1:27 pm

    You must catch InputMismatchException exception like this:

    import java.util.InputMismatchException;
    import java.util.Scanner; 
    public class AreaCircle { 
        public static void main(String[] args) {
            // TODO code application logic here
            Scanner sc = new Scanner(System.in); // read the keyboard
            System.out.println("This program will calculate the area of a circle");
            System.out.println("Enter radius:");//Print to screen
            try {
                double r = sc.nextDouble(); // Read in the double from the keyboard
                double area = (3.14 *r * r);
    
                String output = "Radius: " + r + "\n";
                output = output + "Area: " + area + "\n";
                System.out.println("The area of the circle  is " + area);
    
            }
            catch( InputMismatchException e ) {
                System.out.println("Invalid Input, please enter a number");
                //put a message or anything you want to tell the user that their input was weird.
            }
            catch( NumberFormatException e ) {
                System.out.println("Invalid Input, please enter a number");
                //put a message or anything you want to tell the user that their input was weird.
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the question. write a program that prompts the user to input five
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Similar to this question , except the console program being wrapped up in the
Dear all,Now i have this question in my java program,I think it should be
This is with reference to the below question: Execute program from within a C
This program is supposed to open a txt file, record the answers from two
Original question: This method is supposed to change the image being displayed on a
I just posted this question: How to distribute my Java program so that it
This program is supposed to determine how many units are stored in the value
This is not a pure programming question, however it impacts the performance of programs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.