-
/*Check if string contains valid number example.This example shows how to check if string contains valid numberor not using parseDouble and parseInteger methods ofDouble and Integer wrapper classes.*/
public class CheckValidNumberExample {
public static void main(String[] args) {
String[] str = new String[]{“10.20”, “123456”, “12.invalid”};
for(int i=0 ; i < str.length ; i ++){
if( str[i].indexOf(“.”) > 0 ){
try{/** To check if the number is valid decimal number, use* double parseDouble(String str) method of* Double wrapper class.** This method throws NumberFormatException if the* argument string is not a valid decimal number.*/Double.parseDouble(str[i]);System.out.println(str[i] + ” is a valid decimal number”);}catch(NumberFormatException nme){System.out.println(str[i] + ” is not a valid decimal number”);}
}else{try{/** To check if the number is valid integer number, use* int parseInt(String str) method of* Integer wrapper class.** This method throws NumberFormatException if the* argument string is not a valid integer number.*/
Integer.parseInt(str[i]);System.out.println(str[i] + ” is valid integer number”);}catch(NumberFormatException nme){System.out.println(str[i] + ” is not a valid integer number”);}}}
}}
/*Output would be10.20 is a valid decimal number123456 is valid integer number12.invalid is not a valid decimal number*/
Friday, 13 April 2018
Popular Posts
-
Hands-On Python Mastery: Step by Step Tutorial Introduction Python has become one of the most widely used programming languages because ...
-
The Little Book of Deep Learning Introduction The Little Book of Deep Learning by Franรงois Fleuret is designed as a compact introduction ...
-
Linear Algebra is one of the fundamental areas of mathematics and provides the language for studying vectors, transformations, systems, an...
-
Join Now: September Bootcamp Registration PHASE 1 — Python Foundations (Day 1–5) Day 1: Python & DS Foundations — Setup, Syntax, Data Ty...
-
Learning Data Science becomes much more effective when theoretical concepts are connected with practical projects. 50-Days 50-Projects: Da...
-
Probability and statistics are fundamental to computer science because many computational problems involve uncertainty, incomplete informa...
-
Google AI Student Offer 2026: Get Google AI Pro Free for 1 Year Students can now get more from Google’s AI ecosystem with the Google AI St...
-
What you'll learn Build ML models with NumPy & scikit-learn, build & train supervised models for prediction & binary class...
-
Deep Learning is often introduced through practical frameworks and ready-to-use models, but understanding its mathematical foundations pro...
-
Introduction to Probability for Data Science Introduction Probability is one of the most important mathematical foundations of data scienc...
Categories
100 Python Programs for Beginner
(119)
AI
(343)
Android
(25)
AngularJS
(1)
Api
(7)
Assembly Language
(2)
aws
(31)
Azure
(12)
BI
(10)
book
(1)
Books
(356)
Bootcamp
(14)
C
(78)
C#
(12)
C++
(83)
cloud
(1)
Course
(90)
Coursera
(303)
Cybersecurity
(36)
data
(10)
Data Analysis
(46)
Data Analytics
(31)
data management
(16)
Data Science
(429)
Data Strucures
(18)
Deep Learning
(220)
Django
(16)
Downloads
(3)
edx
(21)
Engineering
(15)
Euron
(30)
Events
(9)
Excel
(24)
Finance
(13)
flask
(4)
flutter
(1)
FPL
(17)
Generative AI
(77)
Git
(13)
Google
(55)
Hadoop
(3)
HTML Quiz
(1)
HTML&CSS
(48)
IBM
(43)
IoT
(3)
IS
(25)
Java
(99)
Leet Code
(4)
Machine Learning
(400)
Meta
(24)
MICHIGAN
(5)
microsoft
(13)
Nvidia
(8)
Pandas
(16)
PHP
(20)
Projects
(35)
Python
(1368)
Python Coding Challenge
(1234)
Python Library
(1)
Python Mathematics
(17)
Python Mistakes
(51)
Python Pattern Challenge
(2)
Python Quiz
(625)
Python Tips
(111)
pythonquiz
(1)
Questions
(3)
R
(72)
React
(7)
Scripting
(3)
security
(4)
Selenium Webdriver
(4)
Software
(21)
SQL
(55)
Udemy
(20)
UX Research
(1)
web application
(11)
Web development
(9)
web scraping
(3)

0 Comments:
Post a Comment