0

# Java loan calculator

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. 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 remain=amount; for(int i=0;i<3;i++){ int payment= (90/100); remain*=payment; } System.out.println(remain); } } //why is my code dont give any output?, what is wrong

26th Mar 2021, 3:58 AM
Jack Van Hoeven
10 ответов
+ 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 int k = amount; int persent; int payment; for (int i = 0 ; i < 3; i++) { persent = k * 10 /100; payment = k - persent; k = payment; } System.out.println(k); } } you must understand about algorithms, by nuari ananda
3rd Jun 2021, 6:43 AM
Nuari Ananda
+ 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 x = 0;x < 3;x++) { amount -= ((amount * 10) / 100); }; System.out.println(amount); } } //Simple
26th May 2022, 12:49 PM
IbrahimCPS
+ 1
Jack Van Hoeven remain = 0.1 * remain amount - =remain
26th Mar 2021, 4:17 AM
+ 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; //your code goes here for(int i=1;i<=3;i++) { loan =amount/10; amount-=loan; } System.out.println(amount); } }
14th Jun 2021, 9:21 AM
Dharmi Sri
0
You need to calculate 10% of the current amount and subtract that 10% from the current amount for each iteration of the loop. Also, if there is a fractional part (part after the decimal) you will need to round the percent up to the next whole number before subtracting from the current amount.
26th Mar 2021, 4:14 AM
ChaoticDawg
0
thanks for help I got the answer from google but I still dont understand why I cant directly multiples the amount(100000) with 90/100, this is the correct answer import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int remain = amount; for (int i = 0 ; i <3; i++) { int payment = (int)Math.ceil(10/100.0*remain); remain -= payment; } System.out.println(remain); } }
26th Mar 2021, 4:31 AM
Jack Van Hoeven
0
Working code: 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 payment = 0; int month = 1; do{ if (amount%10 == 0){ payment = amount/10; amount = amount - payment; } else { payment = amount/10 +1; amount = amount - payment; } month++; } while (month <= 3); System.out.println(amount); } }
20th Apr 2022, 11:39 AM
Vaijnath Satbhai
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 for(int x=3; x!=0; x--){ amount *= 0.9; } System.out.println(amount); } }
22nd May 2022, 10:03 AM
Айдын Мухаметсадыков
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 payment , remainingAmount; for(int i=0; i<3; i++ ) { payment=(10/100)*amount; remainingAmount=amount-payment; System.out.println(remainingAmount); } } }
16th Sep 2022, 5:00 PM
Shital Dhokare
- 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 pay; for(int i = 0; i < 3; i++) { pay = (10*amount)/100; amount -= pay; } System.out.println(amount); } }
8th Feb 2022, 1:58 AM
Ankit Kumar Singh