0

Loan Calculator in java

I solved that without loop and in 2 cases it's run perfect but remaining 3 cases it's not working.

11th Jun 2021, 5:03 AM
Sanny Kumar
5 Respostas
+ 1
Sanny Kumar I have used loop so it will calculate remaining amount after 3 months. If you want to try with your logic then here is some corrections in your logic. 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 m1 = amount * 90 / 100; //int a1 = amount-m1; //int m2 = a1/100*10; m1 = m1 * 90 / 100; // int a2 = a1-m2; // int m3 = a2/100*10; // int a3 = a2-m3; m1 = m1 * 90 / 100; System.out.println(m1); } } See above code with and without loop. Both will work same. But here is only 3 months, suppose when there was different months for different case then?
11th Jun 2021, 5:21 AM
A͢J
A͢J - avatar
0
Sanny Kumar Show your code. Sure without loop you have written Hard Code logic.
11th Jun 2021, 5:04 AM
A͢J
A͢J - avatar
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 m1 = amount/100*10; int a1 = amount-m1; int m2 = a1/100*10; int a2 = a1-m2; int m3 = a2/100*10; int a3 = a2-m3; System.out.println(a3); } }
11th Jun 2021, 5:09 AM
Sanny Kumar
0
Sanny Kumar Hard Code logic can't help you. Try to write generic logic. So you have to use loop here. So just try this logic. int amount = scanner.nextInt(); for (int i = 0; i < 3; i++) { amount = amount * 90 / 100; } System.out.print(amount);
11th Jun 2021, 5:13 AM
A͢J
A͢J - avatar
0
AJ ANANT Print remaining amount after three months
11th Jun 2021, 5:15 AM
Sanny Kumar