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.

Edited by intes77: n/a

2
Contributors
1
Reply
7
Views
7 Years
Discussion Span
Last Post by JamesCherrill
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.