Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CleverLily {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int age = Integer.parseInt(scanner.nextLine());
- double machinePrice = Double.parseDouble(scanner.nextLine());
- double toyPrice = Double.parseDouble(scanner.nextLine());
- double sum = 0;
- int toy = 0, birthday = 10;
- for (int i = 1; i <= age; i++) {
- if (i % 2 == 0) {
- sum += birthday - 1;
- birthday += 10;
- } else {
- toy++;
- }
- }
- sum += toy * toyPrice;
- if (sum >= machinePrice) {
- System.out.printf("Yes! %.2f\n", sum - machinePrice);
- } else {
- System.out.printf("No! %.2f\n", machinePrice - sum);
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class CleverLily {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int age = Integer.parseInt(scanner.nextLine());
- double machinePrice = Double.parseDouble(scanner.nextLine());
- double toyPrice = Double.parseDouble(scanner.nextLine());
- double sum = 0;
- int toy = 0, birthday = 10;
- for (int i = 1; i <= age; i++) {
- if (i % 2 == 0) {
- sum += birthday - 1;
- birthday += 10;
- } else {
- toy++;
- }
- }
- sum += toy * toyPrice;
- System.out.printf(sum >= machinePrice ?"Yes! %.2f\n" : "No! %.2f\n", Math.abs(sum - machinePrice));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement