- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Check if a String is Numeric
Example
You can check if a given string is Numeric as shown in the following program.
import java.util.Scanner; public class StringNumeric { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string ::"); String str = sc.next(); boolean number = str.matches("-?\d+(\.\d+)?"); if(number) { System.out.println("Given string is a number"); } else { System.out.println("Given string is not a number"); } } }
Output
Enter a string :: 4245 Given string is a number
- Related Articles
- Golang Program to Check if a String is Numeric
- C++ Program to Check if a String is Numeric
- Swift Program to Check if a String is Numeric
- Java program to check if string is pangram
- Java Program to check if a string is a valid number
- Java Program to check if a string is empty or not
- Java Program to Check if a String is Empty or Null
- Java Program to Check if a string contains a substring
- Java program to check if a Substring is present in a given String
- Java program to check if a string contains any special character
- Java Program to check whether the character is ASCII 7 bit numeric
- How to check if a unicode string contains only numeric characters in Python?
- Python Program to check whether all elements in a string list are numeric
- C Program to Check if a Given String is a Palindrome?
- How to check if input is numeric in C++?

Advertisements