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());
- int toyPrice = Integer.parseInt(scanner.nextLine());
- double totalPrice = 0;
- int counter = 1;
- int toysCount = 0;
- for (int i = 1; i <= age; i++){
- if (i % 2 == 0){
- totalPrice += 10 * counter;
- counter++;
- }else{
- toysCount++;
- }
- }
- totalPrice -= counter - 1;
- int totalToysPrice = toyPrice * toysCount;
- totalPrice += totalToysPrice;
- if (totalPrice >= machinePrice){
- System.out.printf("Yes! %.2f", totalPrice - machinePrice);
- }else{
- System.out.printf("No! %.2f", machinePrice - totalPrice);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement