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 1001. Reverse Root

What's wrong with my program in Java?
Posted by Petrovskij 10 Jun 2015 06:14
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Scanner;

public class Timus {
    public static void main(String[] args) {
        String regexp = "[\\n?\\s]+";
        Scanner c = new Scanner(System.in);
        String data = c.nextLine();
        String[] numbers = data.split(regexp);

        for (int i = numbers.length - 1; i >= 0; i--) {
            System.out.println(truncateSqrt(numbers[i]));
        }
    }

    private static String truncateSqrt(String s) {
        DecimalFormat fmt = new DecimalFormat("0.0000");
        fmt.setRoundingMode(RoundingMode.DOWN);

        double sqrt = Math.sqrt(Long.parseLong(s));
        return fmt.format(sqrt);
    }
}