Софтуерно Инженерство
Loading...
+ Нов въпрос
penata avatar penata 1 Точки

Homework 08. Traveling At Light Speed Java

Здравейте, боря се със задачата но Judge ми дава 70 точки. Опитах всякакво форматиране, но резултата е същия: грашка на тестове 1,4 и 6.

Това е кода ми:

public class demo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double kmsForLightYear = 9450000000000.0;
        double kmPerSec = 300000.0;
        double lightYears = Double.parseDouble(scanner.nextLine());
        double secondsTotal = (lightYears*kmsForLightYear)/kmPerSec;

        int minutes = (int)secondsTotal/60;
        secondsTotal%=60;
        int hours = minutes/60;
        minutes%=60;
        int days = hours/24;
        hours%=24;
        int weeks = days/7;
        days%=7;
        System.out.printf("%d weeks\n" +
                "%d days\n" +
                "%d hours\n" +
                "%d minutes\n" +
                "%d seconds\n",
        weeks,days,hours,minutes,(int)secondsTotal);
    }
}

Ще съм благодарен, ако някой има идея къде може да е проблема.
0
Technology Fundamentals
DadiEinarsson avatar DadiEinarsson 21 Точки
Best Answer

Maybe I am making it too complicated but I got it right with using BigDecimal as the data type. It makes a little bit more complicated. Here is the link to my code.

https://pastebin.com/jnpTQqbm

 

 

0
penata avatar penata 1 Точки

Thank you. It is not too complicated if it works :) I guess the problem was in the "doubles" that I am using.

0