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

задача Lutenica

Здравейте Колеги,

може ли някой да ми каже, къде се чупи този код?

Получавам 80 от 100 в Judge

import java.util.Scanner;
public class Lutenitsa {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);

            double amountTomato = Double.parseDouble(scanner.nextLine());
            int countBoxes = Integer.parseInt(scanner.nextLine());
            int countJars = Integer.parseInt(scanner.nextLine());
            double lutenica = 5;
            double jarsVolume = 0.535;

            double lutenicaTotal = amountTomato/ lutenica;
            System.out.printf("Total lutenica: %.0f kilograms.%n",lutenicaTotal);

            double jars = lutenicaTotal / jarsVolume;
            double jarsLeft = Math.floor( jars - (countBoxes *countJars));
            double boxes = jars / countJars;

            if (boxes > countBoxes) {
               double boxesLeft = Math.floor(boxes - countBoxes);
                System.out.printf("%.0f boxes left.%n", boxesLeft);
                System.out.printf("%.0f jars left.", jarsLeft);

            } else if (boxes <= countBoxes) {
                double boxesNeeded = Math.floor(countBoxes -boxes);
                double jarsNeeded = Math.floor((countBoxes * countJars) -jars);
                System.out.printf("%.0f more boxes needed.%n",boxesNeeded);
                System.out.printf("%.0f more jars needed.%n",jarsNeeded);
            }
           
        }
    }

 

 

Тагове:
KeepCoding avatar KeepCoding 282 Точки

Здравей колега.

Забравил си да закръглиш надолу с "Math.floor()" ето този ред:

System.out.printf("Total lutenica: %.0f kilograms.%n",lutenicaTotal);

Ако замениш горния ред с долния ще получиш 100/100

System.out.printf("Total lutenica: %.0f kilograms.%n",Math.floor(lutenicaTotal));

 

0
kirilheitmann avatar kirilheitmann 0 Точки

 благодаря много!

0