Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P11HappyCatParking {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numberOfDays = Integer.parseInt(scanner.nextLine());
- int numberOfHours = Integer.parseInt(scanner.nextLine());
- double price = 0;
- for (int days = 1; days <= numberOfDays; days++) {
- double pricePerDay = 0;
- boolean dayIsEven = days % 2 == 0;
- for (int hours = 1; hours <= numberOfHours; hours++) {
- boolean hourIsEven = hours % 2 == 0;
- if (dayIsEven && !hourIsEven) {
- pricePerDay = pricePerDay + 2.5;
- } else if (!dayIsEven && hourIsEven) {
- pricePerDay = pricePerDay + 1.25;
- } else {
- pricePerDay = pricePerDay + 1.0;
- }
- }
- System.out.printf("Day: %d - %.2f leva%n", days, pricePerDay);
- price = price + pricePerDay;
- }
- System.out.printf("Total: %.2f leva", price);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement