Hello! Im a java noob and I need to create a program that determines whether the input is an integer or not , can anyone help me out? thanks in advance! btw I have to use Scanner from java.util. , I have no idea on how to check if its an integer or not. Before, I was using C and in C there's a function called isnum() but since Im new at java I have no idea what to do.
any help is greatly appreciated :)
esy928
0
Light Poster
Recommended Answers
Jump to PostLet's assume that you use Scanner to read input: Scanner.readLine() I think is the method and you store it into a String variable. There is a method that turns the String into an int:
String s = "10"; int i = Integer.parseInt(s);
The int i variable has …
Jump to PostYou can for-loop the String using the charAt method and checking each time if the char taken is one of those: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.' . Also you should check if the '.' appears more than once
Jump to PostSorry for the second post but here is the API for the charAt: String
Jump to PostOK First of all you have to find out what scanner class does. I suggest you check java specifications. best place you check is java specifications.
from here you can get all the …
All 13 Replies
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
esy928
0
Light Poster
esy928
0
Light Poster
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
esy928
0
Light Poster
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
yilmazhuseyin
16
Light Poster
esy928
0
Light Poster
esy928
0
Light Poster
mayursharma
0
Light Poster
lalkundan
0
Newbie Poster
abors
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.