0

Java Loan Question

I ran the Loan Problem from the Java Section in my IDE and it works. It doesn’t work as a solution in SoloLearn. Why?

31st Oct 2021, 2:00 AM
Colin
6 Answers
+ 2
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int count=0; while(count !=3){ amount= (amount-(amount/10)); System.out.println(amount); count+=1; } } }
31st Oct 2021, 3:54 AM
Colin
+ 1
Colin You have to print amount only once which would be final amount
31st Oct 2021, 4:37 AM
A͢J
A͢J - avatar
+ 1
Hahah! Thanks. I just figured that out. So i moved the print statement to outside the while-loop. Thanks again for responding.. Colin
31st Oct 2021, 5:25 AM
Colin
+ 1
Tho the answer given “you only need to print once” waa helpful, a bettwr answer would have been; having the print statement in the “while-loop” will print the statemt 3 times b/c of the condition”while(count !=3). To print once, with the final reault when the condition “count =3” the print statement needs to be placed OUTSIDE the “while-loop’s” closing braces. Thanks Colin
31st Oct 2021, 11:12 PM
Colin
0
Can you post your code here ? Maybe you use something from a newer version. Sololearn has Java version 16.
31st Oct 2021, 2:29 AM
Stefanoo
Stefanoo - avatar
0
The Question: You take a loan from a friend and need to calculate how much you will owe him after 3 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 3 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
31st Oct 2021, 3:54 AM
Colin