0

How can I use here the loops? It is a loan calculator

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //введите код сюда int month1 = amount *10/100; int month2 = month1 *10/100; int month3 = amount- month2*10; int month11 = month3 *10/100; int month22 = month11 *10/100; int month33 = month3 - month22*10; int month111 = month33 *10/100; int month222 = month111 *10/100; int month333 = month33 - month222*10; System.out.println(month333); } }

21st Sep 2021, 5:48 AM
Manasbek Abdugani uulu
Manasbek Abdugani uulu - avatar
4 Answers
+ 5
int amount = scanner.nextInt(); for(int i = 0 ; i <= 2; i++ ){ amount -= (amount *10)/100; } System.out.println(amount );
21st Sep 2021, 6:18 AM
Simba
Simba - avatar
+ 2
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int amount2 = scanner.nextInt(); int interest = 10; int time = 3; int n = 1; for (int i = 1; i <= time; i++) { amount = amount - amount * interest / 100; } System.out.println(amount); //easiest way to do it /************************************/ System.out.println(); while (n < 3) { n++; amount2 = amount2 - amount2 * interest / 100; } System.out.println(amount); }//either one works } using loop is the fastest way to solve this problem.
21st Sep 2021, 6:29 AM
jiaqi chen
jiaqi chen - avatar
+ 2
float v1, v2, v3=0; for (int i = 0; i < 3; i++) { if (i==0) v1=amount; else v1=v3; v1 = v1 *10/100; v2 = v1 *10/100; v3 = v1 - v2 *10; } System.out.println(v3); // Keep learning & happy coding :D
21st Sep 2021, 6:33 AM
SoloProg
SoloProg - avatar
+ 1
Thank you for everyone guys🖐️🖐️🖐️
21st Sep 2021, 6:46 AM
Manasbek Abdugani uulu
Manasbek Abdugani uulu - avatar