Check numbers with exceptions


Tuesday, October 24, 2023 Difficulty: Easy

Objective

Create a Java program that prompts the user to enter a text (x) and uses a try-catch block to check if the text is a number or not. If it''s a number, display "It''s a number"; otherwise, show "It''s not a number."

It''s important to note that there are more suitable ways to validate user input in Java applications.

Input

Juan

Output

It is not a number

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

Check numbers with exceptions

Create a Java program that prompts the user to enter a text (x) and uses a try-catch block to check if the text is a number or not. If it's a number, display "It's a number"; otherwise, show "It's not a number."

Exceptions: try/catch

Practice with easy and intermediate Java exercises on different types of text, numeric or boolean data.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

Exercises C# App

Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play