1,105,169 Community Members

isString,isInt,isDouble function

Member Avatar
intes77
Light Poster
34 posts since Feb 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hello i would like to know how can i use these isString,isInt,isDouble functions.
i really dont have a clue if these functions do exist.

but i want to create a program that lets me input anything.
and it would identify if it is a string an int or a double.
i would be using a String variable.
here's my code.

import java.util.*;
class program
{
public static void main(String[]args)
{
Scanner input=new Scanner(System.in);
String a;

System.out.print("Enter anything: ");
a=input.next();

if(a.isString)
System.out.println("this is a String");
else if(a.isDouble)
System.out.println("this is a Double");
else if(a.isInt)
System.out.println("this is an Int");
else
System.out.println("no comment");

}
}

when i runned this. the error says:
cannot find symbol: variable isString
cannot find symbol: variable isDouble
cannot find symbol: variable isInt.

i need help on how to use these functions.
or any function that could let me identify a string a double and an int
Thanks in advance.

Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

Anything the user types is a String
You can then try to convert the String to integer (etc) by using API methods such as
public Integer(String s) throws NumberFormatException
which will give the the Integer if possible, and throw a NumberFormatException if it cannot be parsed as an Integer.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article