[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Programming questions

Posted on 2006-05-22
6
Medium Priority
?
252 Views
Last Modified: 2010-05-18
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

0
Comment
Question by:tkschultz1207
6 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 16736127
Use String.split
0
 

Author Comment

by:tkschultz1207
ID: 16736971
How do you use String.split?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16736987
String tokens[] = "1234.1214".split("\\.");
String a = tokens[0];
String b = tokens[1];
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 92

Expert Comment

by:objects
ID: 16738263
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
 
LVL 9

Accepted Solution

by:
matthew016 earned 1000 total points
ID: 16747981
[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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16758650
:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question