1.

Write a program Take a real number as an input and display the integral part and the fractional part of thenumber. ​

Answer»

program to PRINT the integer part and fractional part of a GIVEN NUMBER

class IntFraction

{

public static void MAIN(String args[])

{

// input in the form of double

double 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 part

System.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*/

}

}



Discussion

No Comment Found