0

Loan Calculator (JAVA) How is this possible?

In the Java course they asked me to make a Loan calculator. I used the code below to solve this. My question is, how does the line of code below work? Shouldn’t the ouput be zero because 9/10 equals zero? amount = amount * 9/10 CODE I USED IS BELOW: 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 = 1; x <= 6; x++){ amount = amount * 9/10; } System.out.println(amount); } }

12th Dec 2020, 10:06 PM
Sol Sanchez
Sol Sanchez - avatar
9 odpowiedzi
+ 3
Sol , if you place it this way (9/10) in brackets in the equation - yes the output is 0, in the other case it depends - first you multiply amount with 9 then you divide it by 10. As a hint for payment for each month you can use Math.ceil method.
12th Dec 2020, 10:13 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
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.
14th Dec 2020, 2:24 PM
Lam Wei Li
Lam Wei Li - avatar
0
TheWh¡teCat 🇧🇬 That makes more sense, thank you! Considering the order of operations rule (PEMDAS), the code is executed from left to right.
12th Dec 2020, 10:39 PM
Sol Sanchez
Sol Sanchez - avatar
0
Sol , you are welcome 🐱
12th Dec 2020, 10:40 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Who can help me with the Loan Calculator answer? I don't understand Anything! I will thank you
21st Mar 2021, 9:35 PM
kensy Nicolle Gutierrez Flores
kensy Nicolle Gutierrez Flores - 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 rem_amt = amount; for (int i = 1 ; i <= 6 ; i++) { int paid = (int)Math.ceil(10/100.0*rem_amt); rem_amt -= paid ; } System.out.println(rem_amt); } }
18th Mar 2021, 6:59 AM
Vijayanathan Menakan
Vijayanathan Menakan - 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(); int rem_amt = amount; for (int i = 1 ; i <= 6 ; i++) { int paid = (int)Math.ceil(10/100.0*rem_amt); rem_amt -= paid ; } System.out.println(rem_amt); } }
30th Apr 2021, 7:40 AM
Mohamed Malik Turay
- 2
Scanner sc = new Scanner (System.in); int amount = sc.nextInt(); int payment; int rem_Amt; for(int i = 0; i<=3; i++){ payment = amount * 10/100; amount = amount - payment; System.out.println(amount); }
31st May 2021, 6:22 PM
Romi Mawandia
Romi Mawandia - 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(); int rem_amt = amount; for (int i = 1 ; i <= 6 ; i++) { int paid = (int)Math.ceil(10/100.0*rem_amt); rem_amt -= paid ; } System.out.println(rem_amt); } }
30th Apr 2021, 7:37 AM
Mohamed Malik Turay