Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Expression {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int age = Integer.parseInt(scanner.nextLine());
  8. double priceWashingMachine = Double.parseDouble(scanner.nextLine());
  9. int priceForDoll = Integer.parseInt(scanner.nextLine()); //6
  10. double moneyPresent = 10;
  11. double numberDolls = 0;
  12. double moneyFromAllPresents = 0;
  13. int count = 0;
  14.  
  15. for (int i = 1; i<=age; i++){
  16.  
  17. if (i % 2 == 0){
  18.  
  19. moneyFromAllPresents = moneyFromAllPresents + moneyPresent;
  20. moneyPresent = moneyPresent +10;
  21. count++;
  22. }
  23. else {
  24. numberDolls = numberDolls +1;
  25. }
  26. }
  27. moneyFromAllPresents = moneyPresent - count;
  28. double moneyFromDolls = priceForDoll * numberDolls;
  29.  
  30. double allMoney = moneyFromAllPresents + moneyFromDolls;
  31. if ( allMoney > priceWashingMachine){
  32. allMoney = allMoney - priceWashingMachine;
  33. System.out.printf("yes! %.2f",allMoney);
  34. }
  35. if ( allMoney < priceWashingMachine){
  36. allMoney = priceWashingMachine -allMoney;
  37. System.out.printf("No! + %.2f",allMoney);
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement