954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

return data type

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

Nazzy
Newbie Poster
2 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

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

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 

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.

Nazzy
Newbie Poster
2 posts since Mar 2006
Reputation Points: 10
Solved Threads: 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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You