fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner input = new Scanner(System.in);
  13. int month = 1;
  14. int year = 0;
  15.  
  16. double balance;
  17. double rate;
  18. double payment;
  19. double principal;
  20. double calculated_interest;
  21. double actual_payment;
  22. double principal_amt;
  23.  
  24. System.out.println("What is your principal amount?"); principal = input.nextDouble(); balance = principal;
  25. System.out.println("What is your monthly interest rate in decimal?"); rate = input.nextDouble();
  26. System.out.println("What is your monthly payment?"); payment = input.nextDouble();
  27.  
  28.  
  29. while(balance>0){
  30.  
  31. if(month == 13){
  32. year++;
  33. month = 1;
  34. }
  35.  
  36. calculated_interest = ((int)(Math.round(balance*rate*100)))/100.0;
  37. principal_amt = ((int)(Math.round((payment-calculated_interest))*100))/100.0;
  38. actual_payment = ((int)(Math.round((payment-calculated_interest)*100)))/100.0;
  39.  
  40. System.out.println("Year " + year + ", " + "Month " + month + ":");
  41. System.out.println("Your interest amount is " + "$" + calculated_interest);
  42. System.out.println("Your principal amount " + "$" + principal_amt);
  43. balance = ((int)(Math.round((balance-actual_payment)*100)))/100.0;
  44.  
  45. System.out.println("Your new balance is " + "$" + balance);
  46. System.out.println();
  47.  
  48. month++;
  49. }
  50. System.out.println("Not in while");
  51. input.close();
  52. }
  53. }
Success #stdin #stdout 0.07s 711680KB
stdin
-1.0 12.0 12000
stdout
What is your principal amount?
What is your monthly interest rate in decimal?
What is your monthly payment?
Not in while