a method to check if an input number is integer or float or NAN
I am working on a program that inputs a data into a textfield and checks if the number is integer, float or Not a number. i have gotten the layout. But i have a rough idea that if it is an integer there would be no decimal points and decimal point for a float data and i fuser enters characters like "A" or "2M" then it's not a number. But this is my first class with strings and so have no idea how to approach this problem. Any guideline appreciated.I have just gotten a layout.
public class Lab10a extends Applet
private TextField inputTF;
private String inputVal;
public void init()
Label textLbl = new Label("A program to input a string and display the type of the number");
inputTF = new TextField(7);
public void actionPerformed(ActionEvent event)
if(event.getSource() == inputTF)
inputVal = inputTF.getText().trim();
public void paint(Graphics g)
the difficulty that I see is deciding on and then implementing the pattern your program will recognize as being an int or a float/double. The String class methods will allow you to distinguish whether a "token" is a number or not. What will involve your own evaluation and implementation will be how your program will decide whether a sting of digits will be interpreted as an integer or a float.
What will be your "sign of the float"? How will you read that from the token?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center