Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Java double就能过,float 不行,无语public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true){ int min1 = sc.nextInt(); int max1 = sc.nextInt(); int min2 = sc.nextInt(); int max2 = sc.nextInt(); if(min1==0&&min2==0&&max1==0&&max2==0){ break; } if(min1>max1){ int tmp = min1; min1 = max1; max1 = tmp; } if(min2>max2){ int tmp = min2; min2 = max2; max2 = tmp; } double rate1 = (double)max1/min1; double rate2 = (double)max2/min2; NumberFormat nf = NumberFormat.getPercentInstance(); nf.setMaximumIntegerDigits(3); nf.setMinimumFractionDigits(0); nf.setRoundingMode(RoundingMode.DOWN); double r = 0; if(rate1>rate2){ r = (double) max2 / max1; }else{ r = (double) min2 / min1; } if(r<0.01){ r = 0.01f; } if(r>1){ r = 1; } System.out.println(nf.format(r)); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator