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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
String tokens[] = "1234.1214".split("\\.");
String a = tokens[0];
String b = tokens[1];
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.nextTo ken());
int b = Integer.parseInt(st.nextTo ken());
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.nextTo
int b = Integer.parseInt(st.nextTo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
ASKER