Advertisement
Spocoman

Easter Guests

Sep 4th, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double guests = Double.parseDouble(scanner.nextLine()),
  7.                 budget = Double.parseDouble(scanner.nextLine());
  8.  
  9.         budget -= Math.ceil(guests / 3) * 4 + guests * 2 * 0.45;
  10.  
  11.         if (budget < 0) {
  12.             System.out.printf("Lyubo doesn't have enough money.\nHe needs %.2f lv. more.", Math.abs(budget));
  13.         } else {
  14.             System.out.printf("Lyubo bought %d Easter bread and %d eggs.\nHe has %.2f lv. left.", (int) Math.ceil(guests / 3), (int) guests * 2, budget);
  15.         }
  16.     }
  17. }
  18.  
  19. ИЛИ:
  20.  
  21. import java.util.Scanner;
  22.  
  23. public class Main {
  24.     public static void main(String[] args) {
  25.         Scanner scanner = new Scanner(System.in);
  26.         int guests = Integer.parseInt(scanner.nextLine()) * 2;
  27.         double budget = Double.parseDouble(scanner.nextLine())
  28.                 - Math.ceil(1.0 * guests / 3) * 4 + guests * 0.45;
  29.  
  30.         if (budget < 0) {
  31.             System.out.printf("Lyubo doesn't have enough money.\nHe needs %.2f lv. more.", Math.abs(budget));
  32.         } else {
  33.             System.out.printf("Lyubo bought %d Easter bread and %d eggs.\nHe has %.2f lv. left.", (int) Math.ceil(1.0 * guests / 3), guests, budget);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement