ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1457. Heating Main

Why 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 !!!
Posted by Axmadjon 1 May 2014 10:56

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));
    }

}