-
/*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
-
from gtts import gTTS import os def create_audiobook(text_file, output_file): with open(text_file, 'r', encoding='utf-8...
-
This textbook grew out of notes for the ECE143 Programming for Data Analysis class that the author has been teaching at University of Cali...
-
Data Science Crash Course for Beginners with Python... Uncover the energy of records in 30 days with Python Data Science 2024! Are you sea...
-
This practical guide provides a collection of techniques and best practices that are generally overlooked in most data engineering and dat...
-
Through a recent series of breakthroughs, deep learning has boosted the entire field of machine learning. Now, even programmers who know c...
-
from imdb import IMDb ia = IMDb() movie_name = input("Enter the movie name: ") movies = ia.search_movie(movie_name) if movies: ...
-
What you'll learn Play the role of a Data Scientist / Data Analyst working on a real project. Demonstrate your Skills in Python - the ...
-
What you'll learn Create basic visualizations such as line graphs, bar graphs, and pie charts using Excel spreadsheets. Explain the im...
-
import plotly.express as px country = input("Enter the country name: ") data = { 'Country': [country], 'Valu...
-
There are 4 modules in this course Python is now becoming the number 1 programming language for data science. Due to python’s simplicity a...
Categories
AI
(31)
Android
(24)
AngularJS
(1)
Assembly Language
(2)
aws
(17)
Azure
(7)
BI
(10)
book
(4)
Books
(146)
C
(77)
C#
(12)
C++
(82)
Course
(67)
Coursera
(197)
Cybersecurity
(24)
data management
(11)
Data Science
(106)
Data Strucures
(8)
Deep Learning
(13)
Django
(14)
Downloads
(3)
edx
(2)
Engineering
(14)
Excel
(13)
Factorial
(1)
Finance
(6)
flask
(3)
flutter
(1)
FPL
(17)
Google
(20)
Hadoop
(3)
HTML&CSS
(47)
IBM
(25)
IoT
(1)
IS
(25)
Java
(93)
Leet Code
(4)
Machine Learning
(46)
Meta
(18)
MICHIGAN
(5)
microsoft
(4)
Pandas
(3)
PHP
(20)
Projects
(29)
Python
(878)
Python Coding Challenge
(281)
Questions
(2)
R
(70)
React
(6)
Scripting
(1)
security
(3)
Selenium Webdriver
(2)
Software
(17)
SQL
(42)
UX Research
(1)
web application
(8)
0 Comments:
Post a Comment