0

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

4
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by server_crash
0

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

0

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 by pyTony: fixed formating

0

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 by pyTony: fixed formatting

0

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