| | |
return data type
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Solved Threads: 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
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
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
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.
// 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.
•
•
•
•
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.
*Voted best profile in the world*
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
Well, you could write boolean methods like this:
or something like that.
Java Syntax (Toggle Plain Text)
boolean testInt(String s) { try { Integer.parseInt(s); } catch(Exception e) { return false; } return true; }
or something like that.
![]() |
Similar Threads
- Working with SQL server's Image data type (ASP.NET)
- C++ enumerated data type help (C++)
- why is double data type giving an garbage value (Java)
- Problems with changing values returned by RegQueryValueEx (C)
- help on data type conversion (Visual Basic 4 / 5 / 6)
- Help With Data-type Declaration Symbols (Pascal and Delphi)
- Working with SQL's Text data type (ASP.NET)
- Text data type troubles in T-SQL (Database Design)
Other Threads in the Java Forum
- Previous Thread: Simple insertion sort program
- Next Thread: help with JDBC oracle9i
| Thread Tools | Search this Thread |
Tag cloud for Java
account android api applet application array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component data database draw eclipse editor error errors event exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance input integer intellij j2me java javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle print problem program programming project property recursion ria scanner screen search server set size sms smsspam sort sourcelabs splash sql sqlite static string support swing testautomation threads time tree windows






