Hi, can someon help me with the loan calculator in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hi, can someon help me with the loan calculator in java?

I dont know how to proced, i tried int(amount) = scanner.nextInt(); int result = amount % 10; //because i have to pay back 10% of 20000$ each month for 6 months// while(result >= 10628) //10628 is the amount of $ wich i didnt pay yet// { System.out.println (result); amount= scanner.nextInt(); result= amount % 10; } I tried to do a loop with WHILE trying to do the percentage of 20.000 can someone help me, ps sorry for my bad english

30th Nov 2020, 4:18 PM
Michele Marchili
Michele Marchili - avatar
8 Answers
+ 7
Scanner scanner = new Scanner(System.in); int amt = scanner.nextInt(); for(int i=1;i<=6;i++) { int c=(int)Math.ceil(amt*10.0/100.0); amt=amt-c; (here I've used a loop as stated in the question And as soon as the condition is met we can display the output if(i==6) System.out.print(amt); } Happy coding bro😄
30th Nov 2020, 4:55 PM
The INDIAN
The INDIAN - avatar
+ 2
It will be better to share the total code... From the above code instructions : int(amount) is wrong syntax. It shloud be like int amount=scanner.nextInt() ; Remaining works fine..
30th Nov 2020, 4:49 PM
Jayakrishna 🇮🇳
+ 2
Tarun Because the question asks for the outstanding amount after paying for 6 months. If you do the print within the loop, you get the outstanding amount after every month.
5th Jan 2021, 1:15 PM
Lam Wei Li
Lam Wei Li - avatar
+ 1
Thank you man😁
30th Nov 2020, 4:55 PM
Michele Marchili
Michele Marchili - avatar
+ 1
Wait i have another problem, while in the problem it talks about 20'000$ while is trying to run the code try 100'000$ or 500'000 $
30th Nov 2020, 5:05 PM
Michele Marchili
Michele Marchili - avatar
+ 1
Use 90% for 6 months to find the balance. 4 lines of code added. https://code.sololearn.com/cp6GXE4Rc84v/?ref=app If you are paying 10% every month, one way is to find the 10% and then use your total minus the 10% paid to get the balance. The other way, is to find the 90% so you don't have to minus. If you have 100 and you paid 10%, Method 1: 100 - (100 * 10%) = 90 Method 2: 100 * 90% = 90 The "i=0" is used for looping. It will loop from 0 until 5 (< 6), which is 6 times. Finally prints out amount.
30th Nov 2020, 5:52 PM
Lam Wei Li
Lam Wei Li - avatar
0
Why print command need to be written outside of for loop block
5th Jan 2021, 1:09 PM
Tarun
Tarun - avatar
0
Thanks sir. It really helped
5th Jan 2021, 1:20 PM
Tarun
Tarun - avatar