Advertisement
YoannaSt173

lili2

Jan 20th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class lilid {
  4.    
  5.    
  6.    
  7.     public static void main(String[] args){
  8.        
  9.         Scanner scan = new Scanner(System.in);
  10.        
  11.         int age = Integer.parseInt(scan.nextLine());
  12.         double priceOfWashingMachine = Double.parseDouble(scan.nextLine());
  13.         int presentPrice = Integer.parseInt(scan.nextLine());
  14.  
  15.         int numberOfToys = 0;
  16.         int savedMoney = 0;
  17.         int moneyForBirthday = 10;
  18.  
  19.         for (int currentYear = 1; currentYear <= age; currentYear++) {
  20.             if(currentYear % 2 == 0){
  21.                 savedMoney += (moneyForBirthday - 1);
  22.                 moneyForBirthday += 10;
  23.                
  24.                
  25.             } else {
  26.                
  27.                
  28.                 numberOfToys++;
  29.                
  30.             }
  31.         }
  32.        
  33.         savedMoney += numberOfToys * presentPrice;
  34.  
  35.         System.out.println((savedMoney >= priceOfWashingMachine?
  36.                
  37.                 String.format("Yes! %.2f", (savedMoney - priceOfWashingMachine))
  38.                 : String.format("No! %.2f", (priceOfWashingMachine - savedMoney))));
  39.        
  40.        
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement