Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args) {
  7. // write your code hereS
  8. Scanner sc = new Scanner(System.in);
  9. double neededMoney = Double.parseDouble(sc.nextLine());
  10. int neededCents = (int)(neededMoney*100);
  11. int countMonths = Integer.parseInt(sc.nextLine());
  12. double savedMoney = 0;
  13. int savedCents = 0;
  14. for (int i = 1; i <=countMonths ; i++) {
  15.  
  16. if (i%2==1&&i!=1){
  17. savedCents=(int)(savedCents*0.84);
  18. }else if (i%4==0){
  19. savedCents=(int)(savedCents*1.25);
  20. }
  21. savedCents=savedCents+(int)(neededCents*0.25);
  22. if (savedCents-neededCents>=0){
  23. break;
  24. }
  25. }
  26. savedMoney=savedCents/100.00;
  27. if (savedMoney-neededMoney>=0){
  28. System.out.printf("Bravo! You can go to Disneyland and you will have %.2flv. for souvenirs.",savedMoney-neededMoney);
  29. }else{
  30. System.out.printf("Sorry. You need %.2flv. more.", neededMoney-savedMoney);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement