- 2

Java Loan calculator case 5

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //loan amt left int paid;//amount paying double accuamt = amount;//mirror input double accupaid;//amount paying decimals for(int x=1; x<=6; x++) { accupaid = accuamt /10;//finding 10% paid = amount/10; //finding10%to1decimal amount = amount - paid; accuamt =accuamt -accupaid;//reducing total amount if((accuamt % amount)>0){ amount --;}//forcing round down if(x==6) System.out.println(amount);//printing values } } } If I don't force a round down, I always have answer +1. This code works for cases 1-4 :c pls halp. I'm SO CURIOUS. Also I read that Java rounds down integer division so this is confusing me. And we havent learnt abt the rounding function so I tried not to use it, unlike some of the other solutions

24th Dec 2020, 5:43 AM
Jeroen Ow
Jeroen Ow - avatar
7 odpowiedzi
+ 3
Jeroen Ow Well it's a complex code. You can do in just 4-5 step double amount = scanner.nextInt(); for(int x = 1; x <= 6; x++) amount = amount - Math.ceil(amount / 10); System.out.println((int) amount);
24th Dec 2020, 5:49 AM
A͢J
A͢J - avatar
+ 2
Jeroen Ow Yes but we have to use it to get actual result.
24th Dec 2020, 6:08 AM
A͢J
A͢J - avatar
+ 2
Jeroen Ow Congratulations
24th Dec 2020, 6:10 AM
A͢J
A͢J - avatar
+ 1
I Am Groot ! Oh yes, thank you. I did get the 50exp :D
24th Dec 2020, 6:09 AM
Jeroen Ow
Jeroen Ow - avatar
0
I Am Groot ! Well the question didn't say anything about math.ceil or math.floor. :c
24th Dec 2020, 6:07 AM
Jeroen Ow
Jeroen Ow - avatar
0
I Am Groot ! can you please tell me what is Math.ceil?
29th Dec 2020, 7:27 AM
DH R UV
DH R UV - 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.
29th Dec 2020, 6:31 PM
Lam Wei Li
Lam Wei Li - avatar