0

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%

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

2nd Jan 2021, 12:40 PM
Shaik Masthan
Shaik Masthan - avatar
13 ответов
+ 17
import java.util.Scanner; // importing scanner class class HelloWorld { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // creating scanner object for user's import int amount = sc.nextInt(); // reading user's import from scanner object int i = 0; //taking a variable for mounth count while(i<3){ int payBack = (amount*10) /100; // calculating monthly installment e.g its 10% amount = amount - payBack; // calculating remaining amount after monthly installment i++; } /*checking if amount is expected! i printed it outside that loop body because i wanted that final amount which finaly i pay for. when your loop complete its condition then compiler would go for new outline code , and printed that final amount which you need to pay to yout friend. */ System.out.println(amount); } }
10th May 2021, 9:09 PM
Suvin
+ 3
//hope it works 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 months; for (months = 3; months>0; months--) { amount = amount * 90/100; } System.out.println(amount); } }
30th Apr 2021, 2:17 AM
Maniteja
Maniteja - avatar
+ 1
Shaik Masthan , before we can help you, you should show us your attempt first. if you have not done a try by yourself upto now, please do so. Put your code in playground and link it here. Thanks!
2nd Jan 2021, 1:16 PM
Lothar
Lothar - avatar
0
Yaa i did this many times but code showing error
2nd Jan 2021, 1:17 PM
Shaik Masthan
Shaik Masthan - avatar
0
// I am not sure but it works for me 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 numberOfMonth = 0; int remainingAmount = 0; int payment; while(numberOfMonth < 6) { payment = (10 * amount) / 100; remainingAmount = amount - payment; amount = remainingAmount -1; numberOfMonth++; } System.out.println(remainingAmount); } }
16th Mar 2021, 1:53 PM
Lucky Junihardi
Lucky Junihardi - avatar
0
this is the correct answer but first do an effort then try my code. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double amount = scanner.nextInt(); //your code goes here int i=0; double payment; for(i=0;i<3;i++){ payment=0.1*amount; amount=amount-payment; } System.out.println((int)amount); } }
5th May 2021, 5:29 AM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar
0
Here is the answer you are looking for :) 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 pay; for(int i=1; i<=3;i++) { pay = 10*amount/100; amount = amount - pay; } System.out.println(amount); } }
11th Jun 2021, 12:39 PM
Jyoti Soni
Jyoti Soni - avatar
0
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Amount; System.out.println("Enter amount you want to borrow:"); Amount = scanner.nextInt(); int Payment ; for (int i = 1; i <= 3; i++) { Payment = 10 * Amount/100; Amount = Amount - Payment; } System.out.println(Amount); }
16th Sep 2021, 2:13 PM
Peter Aro
Peter Aro - avatar
0
After several efforts I got the answer! . . . import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //double remain = amount; int i; int payment; //your code goes here for(i = 0; i < 3; i++) { payment = (10*amount)/100; amount = amount-payment; } System.out.println(amount); } }
27th Sep 2021, 3:53 PM
Melese Bekele
Melese Bekele - avatar
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 for(int i=1; i<=3; i++){ int payment; payment= amount * 10/100; amount= amount - payment; } System.out.println(amount); } }
4th Mar 2022, 1:16 PM
kirolos shoukri
- 1
Search keyword 'loan' in Q&A you will find posts about this problem, for a quick fix change line in loop to : Amount-=amount/10.0 One such link: https://www.sololearn.com/Discuss/2640825/?ref=app
2nd Jan 2021, 2:26 PM
Daljeet Singh
Daljeet Singh - avatar
- 2
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //my code start here for (int i = 0; i < 6; i++) { amount = amount - ((amount*10)/100); } System.out.println(--amount); } }
2nd Jan 2021, 1:18 PM
Shaik Masthan
Shaik Masthan - avatar
- 3
This is the code i did
2nd Jan 2021, 1:19 PM
Shaik Masthan
Shaik Masthan - avatar