Please! Help Me on This...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Please! Help Me on This...

  1. #1
    Join Date
    Aug 2004
    Location
    Philippines
    Posts
    17

    Unhappy Please! Help Me on This...

    hi!,
    can anyone help me because I don't know about this but I try it but it won't work their is an error and I don't know how, Please Help me...
    my problem is that once I Enter a Real Number the word Valid will display and if it is not a Real Number the word Invalid will display and I have a Java Code on it but the problem it that it won't work and can anyone help me on this, Please...
    Thank You Very Much if anyone can help me on this...

    And the Java Code is here:, If anyone see this Please Help Me what's the problem of my Java Code: Please...


    import java.io.*;
    import java.util.StringTokenizer;
    public class Az
    {
    static BufferedReader n=new BufferedReader
    (new InputStreamReader(System.in));
    private String words[] = new String[0];
    private String desc[] = {"0"};
    private String reserve[] = {"0"};
    private int wordcount;
    private String output = "";
    public static void main(String[]args)throws IOException
    {
    String entry ="";
    Az az = new Az();
    while(true)
    {
    System.out.print("\nEnter Expression: ");
    entry = String.valueOf(n.readLine());
    az.TokenizeString(entry);
    }
    }

    public void TokenizeString(String entry)
    {
    StringTokenizer st = new StringTokenizer(entry);
    int i=0;
    wordcount = st.countTokens();
    while(st.hasMoreTokens())
    { words[i] = st.nextToken(); i++;
    String description = "Valid";
    }
    for(int x=0;x<wordcount;x++)
    { System.out.println("[" +words[x]+ "]: " +Descriptor(words[x])); }
    }
    public String Descriptor(String word)
    {
    String description = "Invalid";
    int x,y;
    for(x=0;x<reserve.length;x++)
    {
    if(word.equalsIgnoreCase(reserve[x]))
    { description = desc[x]; }
    }
    return description;
    }
    }

  2. #2
    Join Date
    Jun 2005
    Location
    Chennai
    Posts
    10

    Smile Happy programming...

    I think the following code helps you... Try to run it.


    import java.io.*;
    import java.util.StringTokenizer;
    public class Az
    {
    static BufferedReader n=new BufferedReader(new InputStreamReader(System.in));

    private String words[] = new String[0];
    private String desc[] = {"0"};
    private String reserve[] = {"0"};
    private int wordcount;
    private String output = "";

    public static void main(String[]args)throws IOException
    {
    String entry ="";
    Az az = new Az();
    //while(true)
    {
    System.out.print("\nEnter Expression: ");
    entry = String.valueOf(n.readLine());
    az.find( entry);

    }
    }

    public void find ( String entry ) {
    StringTokenizer st = new StringTokenizer(entry);
    words = new String[ st.countTokens()];
    wordcount = st.countTokens();

    for( int i=0;i<wordcount;i++) {
    words[i] = st.nextToken();
    }

    String description;
    for ( int i=0;i< words.length;i++) {
    description = "valid";
    try {
    Double.parseDouble( words[i].trim());

    // If you want the number should have decimal point then
    // uncomment the following
    /*if( words[i].indexOf(".")<0) {
    description = "invalid";
    }*/

    }catch ( NumberFormatException ex ){
    description = "invalid";
    }catch ( Exception e ){
    description = "invalid";
    }

    System.out.println("[ "+words[i]+" ] :"+description);

    }

    }
    /*public void TokenizeString(String entry)
    {

    StringTokenizer st = new StringTokenizer(entry);
    words = new String[ st.countTokens()];
    int i=0;
    wordcount = st.countTokens();
    while(st.hasMoreTokens())
    {
    words[i] = st.nextToken();
    i++;
    String description = "Valid";
    }
    for(int x=0;x<wordcount;x++)
    {
    System.out.println("[" +words[x]+ "]: " +Descriptor(words[x])); }
    }

    public String Descriptor(String word)
    {
    String description = "Invalid";
    int x,y;
    for(x=0;x<reserve.length;x++)
    {
    if(word.equalsIgnoreCase(reserve[x]))
    {
    description = desc[x];
    }
    }
    return description;
    }*/
    }




    Now is your intend is over...

    OK..

    Happy programming

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center