DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005
    Posts
    4

    a method to check if an input number is integer or float or NAN

    Hello,
    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.

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class Lab10a extends Applet
    implements ActionListener
    {

    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);

    add(textLbl);
    add(inputTF);

    inputTF.addActionListener(this);

    }

    public void actionPerformed(ActionEvent event)
    {
    if(event.getSource() == inputTF)
    inputVal = inputTF.getText().trim();

    repaint();
    }


    public void paint(Graphics g)
    {



    }
    }


    thanx,
    kt

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links