[PROBLEM SOLVED] loan calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

[PROBLEM SOLVED] loan calculator

i wrote this code for the loan calculator : 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=0 ; i<3 ; i++){ int payment= ((amount*10)/100); int remaining = amount - payment ; System.out.println(payment); System.out.println(remaining); amount = remaining ; } } } the code is correct and even the expected outputs turn out correct but the website doesnt accept the code ! any idea why ?

28th Mar 2021, 12:16 AM
Yasamin Bayrami
Yasamin Bayrami - avatar
27 Answers
+ 34
It would be good to check results in expected output. I mean you can compare your output with the expected output. You need to get output outside for loop to avoid getting several amounts. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int remaining = amount ; //your code goes here for(int i=0 ; i<3 ; i++){ int payment= ((amount*10)/100); remaining = amount - payment ; //System.out.println(payment); amount = remaining ; } System.out.println(remaining); } }
28th Mar 2021, 1:04 AM
Simba
Simba - avatar
+ 17
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 = 0;x < 3;x++) { amount -= ((amount * 10) / 100); }; System.out.println(amount); } } //Simple!
26th May 2022, 12:48 PM
IbrahimCPS
IbrahimCPS - avatar
+ 6
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int loan; //your code goes here for(int i=1;i<=3;i++) { loan =amount/10; amount-=loan; } System.out.println(amount); } }
14th Jun 2021, 9:18 AM
Dharmi Sri
Dharmi Sri - avatar
+ 5
Jamie Hershberger the letter i is just a random name of an integer variable. You can use any name you want for that. for(int Jamie = 0 ; Jamie<months ; Jamie++)
10th Feb 2022, 5:49 AM
Simba
Simba - avatar
+ 4
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 i=1 ; i<=3 ; i++){ int payment= ((amount*10)/100); amount -= payment ; } System.out.println(amount); } }
14th Nov 2021, 6:36 AM
Supun Abeysinghe
Supun Abeysinghe - avatar
+ 3
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=0;i<3;i++){ amount-=(amount*0.1); } System.out.println(amount); } }
11th Jul 2022, 11:27 AM
Prabesh
+ 2
Here is my answer: import java.util.Scanner; public class Programm{ public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int amount=scanner.nextInt(); int remaining=amount; for(int i=0;i<3;i++){ //System.out.println("Month number: "+i); int toPay=(amount*10)/100; remaining=amount-toPay; //System.out.println(toPay); amount=remaining; } System.out.println(remaining); } }
29th Sep 2021, 1:44 PM
Hasnae BOUHMADY
Hasnae BOUHMADY - avatar
+ 1
Isn't it better ? Without loop ?it is working fine. Why I need to use loop here ??? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here int amount1 = amount * 90/100; int amount2 = amount1 * 90/100; int amount3 = amount2 * 90/100; System.out.println(amount3); } }
12th Aug 2021, 7:06 AM
mzurek79
mzurek79 - avatar
+ 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 loan; for (int i = 1; i <= 3; i++) { loan = amount / 10; amount -= loan; } System.out.println(amount); } }
7th Dec 2021, 5:57 PM
Hardi9064
+ 1
Simply this code of mine could do for you it's simple and no advanced syntax is used 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 remain = amount / 10; amount = amount - remain; /* If you want it to display the Value for each month which In this case three months Cause our loop is limited to Three times "x>3" You simply type the printing Part here before this curly brace below */ } System.out.println(amount); } }
29th Jul 2022, 1:15 AM
SAN CTI
SAN CTI - avatar
+ 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 i = 0 ; //your code goes here if (amount>0){ while(i<3){ amount=amount- (amount*10/100); i++; } System.out.println (amount ); } } }
4th Oct 2022, 6:54 PM
Ionut Piturlea
Ionut Piturlea - avatar
+ 1
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 i=1; while( i<=3){ int payment = ((amount *10)/100); amount = amount - payment; i++; } System.out.println(" "+amount); } }
22nd Nov 2022, 6:40 AM
Thành Đặng
Thành Đặng - avatar
0
Simba it WORKED . thank you!
28th Mar 2021, 10:41 PM
Yasamin Bayrami
Yasamin Bayrami - avatar
0
Loan Calculator problem This is right code for this problem my both case got right 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=0;i <3; i++){ int payment = ((amount*10)/100); int remaning = amount - payment ; amount = remaning; System.out.println(amount); } } This is is giving both conditions true if you don't want to use loop then u can repeat the condition 3 time by writing them and at last conditon you can print amout that is last answer. If you guys want that program also msg me i will upload that also for you.... By:- ∆√@¥ ♥ Kūmb#à®
30th Jun 2021, 6:39 AM
Ajay Kumbhar
Ajay Kumbhar - avatar
0
WORKS!
29th Sep 2021, 4:07 PM
Lia Batlle Figueras
Lia Batlle Figueras - 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 int loan; for(int i=1;i<=3;i++) { loan =amount/10; amount-=loan; } System.out.println(amount); } }
15th Oct 2021, 2:34 AM
Emmanuel Sabalboro
Emmanuel Sabalboro - avatar
0
SIMPLIEST SOLUTION 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=0;i<3;i++) { amount-=amount/10; } System.out.println(amount); } }
20th Oct 2021, 4:39 PM
fallen
fallen - avatar
0
for (int i=0 ; i<1 ; i++){ int payment= ((amount*10)/100); int remaining= amount - payment; //System.out.println(payment); //System.out.println(remaining); amount=remaining; } {int payment= ((amount*10)/100); int remaining= amount - payment; //System.out.println(payment); //System.out.println(remaining); amount=remaining;} int payment= ((amount*10)/100); int remaining= amount - payment; //System.out.println(payment); System.out.println(remaining); amount=remaining; simple layout in 3 steps
31st Oct 2021, 11:30 PM
jay
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 payment; int ramount = amount ; for(int i=0;i<=2;i++){ payment=(10*amount)/100; ramount=amount-payment; amount = ramount; } System.out.println(ramount); } }
14th Nov 2021, 3:03 AM
anirudh
anirudh - 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 int months = 3; for(int i=0 ; i<months ; i++) amount = (amount*90/100); System.out.println(amount); } } this is the right code for calculating loan
29th Jan 2022, 5:24 PM
Sunil_k
Sunil_k - avatar