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); } }
4 Answers
+ 5
int amount = scanner.nextInt();
for(int i = 0 ; i <= 2; i++ ){
amount -= (amount *10)/100;
}
System.out.println(amount );
+ 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.
+ 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
+ 1
Thank you for everyone guysđď¸đď¸đď¸