Link to home
Start Free TrialLog in
Avatar of tkschultz1207
tkschultz1207

asked on

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

SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tkschultz1207
tkschultz1207

ASKER

How do you use String.split?
String tokens[] = "1234.1214".split("\\.");
String a = tokens[0];
String b = tokens[1];
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());
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)