944,156 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4101
  • Java RSS
Mar 7th, 2006
0

return data type

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nazzy is offline Offline
2 posts
since Mar 2006
Mar 8th, 2006
0

Re: return data type

Do you have any test data that we could see? What is an expected input and then the corresponding output?
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Mar 8th, 2006
0

Re: return data type

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nazzy is offline Offline
2 posts
since Mar 2006
Mar 8th, 2006
0

Re: return data type

Quote originally posted by Nazzy ...
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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 8th, 2006
0

Re: return data type

Well, you could write boolean methods like this:

Java Syntax (Toggle Plain Text)
  1.  
  2. boolean testInt(String s)
  3. {
  4. try
  5. {
  6. Integer.parseInt(s);
  7. }
  8. catch(Exception e)
  9. {
  10. return false;
  11. }
  12. return true;
  13. }

or something like that.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: applet to object in IE6
Next Thread in Java Forum Timeline: help with JDBC oracle9i





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC