该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
晕,怎么那么简洁
import java.util.*;
public class DoubleTo {
private static int high,low;
private static void read(){
Scanner in=new Scanner(System.in);
System.out.println("输入数据:");
String number=in.nextLine();
int point=number.length()-1-number.indexOf('.');
double low=1;
for(low=1;low
}
double high=Double.parseDouble(number)*low;
DoubleTo.low=(int) low; DoubleTo.high=(int) high;
}
private static void find(double high,double low){
int big=0;
for(int i=0;i<=high;i++){
if(high%i==0&&low%i==0){
big=i;
}
}
DoubleTo.low=(int) low/big; DoubleTo.high=(int)high/big;
}
public static void main(String[]args){
read();
find(high,low);
System.out.println("分数形式为"+high+"/"+low);
}