I'm testing this code in Java with a problem from a programming Judge and I get a "time limit" error. I guess the scanner.hasNextDouble() thingy is not working somehow.
It works with the public inputs shown in the link but it throws this time limit error with the privates.
Any idea to solve this issue?
import java.util.Scanner;
import java.text.NumberFormat;
import java.util.Locale;
class Main /*AvalPoli2*/ {
public static void main(String[] args) {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); // dot sep.
nf.setGroupingUsed(false); // don't group in groups of 3
nf.setMaximumFractionDigits(4);
nf.setMinimumFractionDigits(4);
Scanner scanner = new Scanner(System.in);
scanner.useLocale(Locale.US); // read doubles with dot separator
double sum = 0.0000;
double x = 0;
if (scanner.hasNextDouble()) x = scanner.nextDouble();
while (scanner.hasNextDouble()) {
sum *= x;
sum += scanner.nextDouble();
}
System.out.println(nf.format(sum));
}
}
Thank you very much! ^_^