Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class smartLily {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int age = Integer.parseInt(input.nextLine());
- double washingMachinePrice = Double.parseDouble(input.nextLine());
- int toyPrice = Integer.parseInt(input.nextLine());
- int totalToysCollected=0;
- double moneySaved=0;
- for (int i = 1; i <= age; i++) {
- if(i%2==1){
- totalToysCollected++;
- }else{
- moneySaved+=i/2*10;
- moneySaved-=1.00;
- }
- }
- double totalToysPrice = totalToysCollected*toyPrice;
- double totalMoney=totalToysPrice+moneySaved;
- if(washingMachinePrice<=totalMoney){
- double leftover=totalMoney-washingMachinePrice;
- System.out.printf("Yes! %.2f",leftover);
- }else{
- double notEnoughMoney=washingMachinePrice-totalMoney;
- System.out.printf("No! %.2f",notEnoughMoney);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment