Write a program for enter decimal number and display the number in fraction.
[ Read decimal number as string ]
import java.util.*;
class DecimalPoint {
public static void main(String args[]) {
String str;
double temp;
int i = 1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number : ");
str = sc.nextLine();
double num = Double.parseDouble(str);
do {
temp = num * i;
i++;
}while(temp%1 != 0);
System.out.println(temp + "/" + (i-1));
}
}
0 Comments