Programming questions

I need to write a program where you enter a decimal number:

1234.1214

and the program returns the numbers in  front of the decimal point and the numbers after the decimal point so the out put would look like this

a= 1234
b= 1214

tkschultz1207Asked:
Who is Participating?
 
matthew016Commented:
[javadoc]
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split  method of String or the java.util.regex package instead.

The following example illustrates how the String.split method can be used to break up a string into its basic tokens:

         String[] result = "this is a test".split("\\s");
         for (int x=0; x<result.length; x++)
             System.out.println(result[x]);
     
0
 
CEHJCommented:
Use String.split
0
 
tkschultz1207Author Commented:
How do you use String.split?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
CEHJCommented:
String tokens[] = "1234.1214".split("\\.");
String a = tokens[0];
String b = tokens[1];
0
 
objectsCommented:
Use parseInt() to parse the values

int a = Integer.parseInt(tokens[0]);
int b = Integer.parseInt(tokens[1]);

You could also use a StringTokenizer

String s = "1234.5678";
StringTokenizer st = new StringTokenizer(s, ".");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.