#javaPB Задача New House. Проблем с въвеждане на int от конзолата
Здравейте имам следния проблем: въвеждам от конзолата един string i два int, но програмата не ми дава да стигна до въвеждане на int, изписвайки следната грешка:
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:668)
at java.base/java.lang.Integer.parseInt(Integer.java:776)
at NewHouse.main(NewHouse.java:7)
Ето го и кода ми:
import java.util.Scanner; public class NewHouse { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String flower = scanner.next(); int quantityFlowers = Integer.parseInt(scanner.nextLine()); int budget = Integer.parseInt(scanner.nextLine()); double finalCost = 0.00; if ("Roses".equals(flower)) { double cost = quantityFlowers * 5; if (quantityFlowers >= 80) { double discount = cost * 0.9; finalCost = cost - discount; } }else if ("Dahlias".equals(flower)) { double cost = quantityFlowers * 3.8; if (quantityFlowers >= 90) { double discount = cost * 0.85; finalCost = cost - discount; } }else if ("Tulips".equals(flower)) { double cost = quantityFlowers * 2.8; if (quantityFlowers >= 80) { double discount = cost * 0.85; finalCost = cost - discount; } }else if ("Narcissus".equals(flower)) { double cost = quantityFlowers * 3; if (quantityFlowers >= 120) { double discount = cost * 0.85; finalCost = cost - discount; } }else if ("Gladiolus".equals(flower)) { double cost = quantityFlowers * 2.5; if (quantityFlowers >= 80) { double discount = cost * 0.8; finalCost = cost - discount; } } if ( budget <= finalCost) { double moneyLeft = finalCost - budget; System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.", quantityFlowers, flower, moneyLeft); }else if (budget > finalCost) { double moneyNeeded = budget - finalCost; System.out.printf("Not enough money, you need %.2f leva more.", moneyNeeded); } } }
Много благодаря!