ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1457. Heating Main

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

}