|
|
back to boardWhy this Java code get WA4 ? Please Help !!! Posted by ZARHANE 22 Nov 2010 06:28 import java.text.NumberFormat; import java.util.Scanner; public class Heatingmain { public static void main(String argv[]) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(6); nf.setMinimumFractionDigits(6);
Scanner s = new Scanner(System.in);
double somme=0; double n = s.nextLong(); for (int i = 0; i < n; i++) { somme += s.nextLong(); } System.out.print(nf.format(somme/n)); }
} Edited by author 25.11.2010 03:26 Re: Why this Java code get WA4 ? Please Help !!! Posted by ZARHANE 25 Nov 2010 03:28 The solution is to use format method of String class !!! System.out.print(String.format("%.6f",somme)); But still don't understand why the format method of NumberFormat class doesn't work !!! Edited by author 25.11.2010 03:30 Re: Why this Java code get WA4 ? Please Help !!! import java.util.Scanner; public class AcmTimusRu { public static void main(String argv[]) { String[] nf = new String[0]; Scanner s = new Scanner(System.in); double somme = 0; double n = s.nextLong(); for (int i = 0; i < n; i++) { somme += s.nextLong(); } System.out.print((somme / n)); } } |
|
|