Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine()),
- hours = Integer.parseInt(scanner.nextLine());
- double total = 0;
- for (int day = 1; day <= days; day++) {
- double sum = 0;
- for (int hour = 1; hour <= hours; hour++) {
- if (day % 2 == 1) {
- if (hour % 2 == 1) {
- sum += 1.00;
- } else {
- sum += 1.25;
- }
- } else {
- if (hour % 2 == 1) {
- sum += 2.50;
- } else {
- sum += 1.00;
- }
- }
- }
- System.out.printf("Day: %d - %.2f leva\n", day, sum);
- total += sum;
- }
- System.out.printf("Total: %.2f leva\n", total);
- }
- }
- Решение с тернарен опеаратор:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine()),
- hours = Integer.parseInt(scanner.nextLine());
- double total = 0;
- for (int day = 1; day <= days; day++) {
- double sum = 0;
- for (int hour = 1; hour <= hours; hour++) {
- sum += day % 2 == 1 ? (hour % 2 == 1 ? 1.00 : 1.25) : (hour % 2 == 1 ? 2.50 : 1.00);
- }
- System.out.printf("Day: %d - %.2f leva\n", day, sum);
- total += sum;
- }
- System.out.printf("Total: %.2f leva\n", total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement