Hello,

I am having a lot of difficulty with this program. I have to find the data types of strings that have been inputted by users into the command line. I have used StringTokenizer to break data into strings but I am not sure where to go from there. How do I take these tokens and find out what data types they are.

Thanks

Do you have any test data that we could see? What is an expected input and then the corresponding output?

This is what i have so far:

// File: Classify.java

// Purpose: classifies input into primitive types or String

   import java.io.*;
   import java.util.StringTokenizer;

   public class Classify {

       public static void main(String[] args) throws IOException {
       BufferedReader in = new BufferedReader(
                     new InputStreamReader(System.in));
       String str = in.readLine();
       while (str != null) {
           StringTokenizer tokenizer = new StringTokenizer(str);
           while (tokenizer.hasMoreTokens()) {
           String token = tokenizer.nextToken();




                   }

           str = in.readLine();
       }
       } // main

   } // class Classify

Thanks.

Edited 3 Years Ago by pyTony: fixed formating

This is what i have so far:

// File: Classify.java

// Purpose: classifies input into primitive types or String

   import java.io.*;
   import java.util.StringTokenizer;

   public class Classify {

       public static void main(String[] args) throws IOException {
       BufferedReader in = new BufferedReader(
                     new InputStreamReader(System.in));
       String str = in.readLine();
       while (str != null) {
           StringTokenizer tokenizer = new StringTokenizer(str);
           while (tokenizer.hasMoreTokens()) {
           String token = tokenizer.nextToken();




               }

       str = in.readLine();
   }
   } // main
} // class Classify

Thanks.

Erm, that's not test data, that's your program. Tee he he.

Edited 3 Years Ago by pyTony: fixed formatting

Well, you could write boolean methods like this:

boolean testInt(String s)
{
   try
   {
      Integer.parseInt(s);
   }
   catch(Exception e)
   {
      return false;
   }
   return true;
}

or something like that.

This article has been dead for over six months. Start a new discussion instead.