InterviewSolution
Saved Bookmarks
| 1. |
Write a program to assgin any real number, separate integer part, fractional part and display both |
|
Answer» tion:class IntFraction{PUBLIC static void main(String ARGS[]){// input in the form of doubledouble input=23445.781271;/* convert the double to string and split the string by decimal point(.)*/String str[]=Double.toString(input).split("\\.");//then str[0] will have the integer PART and str[1] will have fraction partSystem.out.println("Decimal Number :"+input);System.out.println("Integer Part:"+str[0]);System.out.println("Fractional Part :"+str[1]);/* Note : use ("\\.") to split a string because just (.) represent split a string with any CHARACTER in terms of regular expression*/}} |
|