Loan Calculator Problem | Sololearn: Learn to code for FREE!

+3

Loan Calculator Problem

I need some help. According to this question my input and output have a difference of 1 number in months 5 here is 1313 I have 1312 and rest of the program is okay That is why output is (10629) not as expected. You take a loan from a friend and need to calculate how much you will owe him after 6 months. You are going to pay him back 10% of the remaining loan amount each month. Create a program that takes the loan amount as input, calculates and outputs the remaining amount after 6 months. Sample Input: 20000 Sample Output: 10628 Here is the monthly payment schedule: Month 1 Payment: 10% of 20000 = 2000 Remaining amount: 18000 Month 2 Payment: 10% of 18000 = 1800 Remaining amount: 16200 Month 3: Payment: 10% of 16200 = 1620 Remaining amount: 14580 Month 4: Payment: 10% of 14580 = 1458 Remaining amount: 13122 Month 5: Payment: 10% of 13122 = 1313 Remaining amount: 11809 Month 6: Payment: 10% of 11809 = 1181 Remaining amount: 10628 https://code.sololearn.com/cQCKlK9H1NGe/?ref=a

12/12/2020 11:35:09 AM

Mahad Ahmed

25 Answers

New Answer

+14

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for (int x = 1; x <= 6; x++){ amount = amount * 9 / 10; } System.out.println(amount); } }

+19

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); for (int x = 0; x <3; x++){ int actual_amount = (amount * 10)/100; amount = amount - actual_amount; } System.out.println(amount); } }

+3

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); for (int x = 0; x <3; x++){ int actual_amount = (amount * 10)/100; amount = amount - actual_amount; } System.out.println(amount); //your code goes here } }

+2

Thank You guys I find it very useful to multiply the amount by 9/10 which is almost equal to 0.10 And Maths.ceil() also does the same thing Most interesting part is that dividing the amount by Double or Float 10.0 does the exact same job but not with Int 10?

+1

You calculate the amount for 10% with an integer, which is not so fine. Please analize yourself why? This is important to understand it if you will code in the future for industry. The solution is: for(int x = 0; x < 6; x++) { amount -= amount / 10.0; } System.out.println(amount);

+1

you can see my answer here https://www.sololearn.com/discuss/2624379/?ref=app

+1

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int total = 0; int tenP; //Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U for(int i=0; i<3; i++){ tenP = (amount*10)/100; total = amount - tenP; amount = total; } System.out.println(total); } }

0

Mahad Ahmed Don't use Math.round() Use Math.ceil()

0

Mahad Ahmed Do this:- for (months = 6; months>0; months--) { amount = amount - Math.ceil(amount * 10/100); } } System.out.println((int) amount);

0

Tried many ways too but in my solution I just multiplied the amount by the 90%(9/10) at each iteration..

0

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes h for(int i=1 ; i<= 6 ; i++){ amount = amount - (amount/ 10); } System.out.println(amount); } } //The output I'm getting is one greater than the desired output//

0

whenever I code different code for this question. I got "No output". can you explain the reason for that?

0

This code gives a correct output: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes h for(int i=1 ; i<= 6 ; i++){ amount = amount - (amount/ 10); } System.out.println(amount-1); } }

0

public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here int numOfMonths=1; int payment; int remainingAmount; while(numOfMonths<=3){ payment=(10*amount)/100; remainingAmount=(amount-payment); amount=remainingAmount; numOfMonths++; } System.out.println(amount);

0

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes h for(int i=1 ; i<= 3 ; i++){ amount = amount - (amount/ 10); } System.out.println(amount); } } // this is for after 3 month

0

Solved! check out my solution here: https://www.sololearn.com/learning/eom-project/1068/949 My solution: (1) change data types from double to int. (2) then cast from double to int. (3) subtract amount from payment to get amount.

0

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); for (int x = 0; x <3; x++){ int actual_amount = (amount * 10)/100; amount = amount - actual_amount; } System.out.println(amount); } }

0

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); // your code goes here int x = 0; do{ x++; int y = (amount * 10)/100; amount -= y; } while(x < 3); System.out.println(amount); } }

0

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int total=0; for (int i = 1; i <= 3; i++){ total = amount * 10 / 100; amount=amount-total; } System.out.println(amount); } }

0

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here int b=0; for(int a=1;a<=3;a++){ b=amount/10; amount=amount-b; } System.out.print(amount); } }