0

20 code project: Loan Calculator

I need help with the Code Project: Loan Calculator. I've tried using an if statement with some else if statements and I've also tried using a for loop but I can't seem to figure out what to do.

2nd Feb 2022, 7:44 PM
Taylor Frye
9 Antworten
0
//This is the simplest answer, reply if you have any questions. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); for(int i = 0; i < 3; i++){ amount = amount * 90/100; } System.out.println(amount); } }
2nd Feb 2022, 9:23 PM
Qais Hweidi
+ 1
Pls Share your try here with task description...
2nd Feb 2022, 7:51 PM
Jayakrishna 🇮🇳
+ 1
Qais Hweidi thanks for your help.
3rd Feb 2022, 9:01 PM
Taylor Frye
+ 1
Taylor Frye This is the simplest way import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int x,r=0,payment; //your code goes here for(x=1;x<=3;x++) { payment=(10*amount)/100; r=amount-payment; amount=r; } System.out.println(r); } } Hope you find it easy.
4th Feb 2022, 7:36 AM
ANMOL SAROHA
ANMOL SAROHA - avatar
0
Here are the if and else if statements that I've tried: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int payment = 0; if (payment = 20000) { System.out.println("Payment: 10% of 20000 = 2000"); System.out.println("Remaining amount: 18000"); } else if { System.out.println("Payment: 10% of 18000 = 1800"); System.out.println("Remaining amount: 16200"); } else if { System.out.println("Payment: 10% of 16200 = 1620"); System.out.println("Remaining amount: 14580"); } } }
2nd Feb 2022, 8:18 PM
Taylor Frye
0
And here is the for loop that I've tried import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int rAmount = amount*0.1 for (int x=0; x<=20000; x*0.1) { System.out.println(amount); System.out.println(rAmount); } } }
2nd Feb 2022, 8:22 PM
Taylor Frye
0
// if (payment = 20000) { //use == , over =. //the = assignment operator //the == is comparision operator //put output only what they ask in description,no extra characters even,not less also for code coach to pass } else if { //where is condition for if statement? Invalid statements now theses.. // } else if { //same System.out.println("Remaining amount: 14580"); } } } Right way sample ex: is else if (amount<=20000) { //statements. // } for else block: syntax: if(condition) { //statements } else{ //statements }
2nd Feb 2022, 8:58 PM
Jayakrishna 🇮🇳
0
int amount = scanner.nextInt(); int rAmount = amount*0.1 for (int x=0; x<=20000; x*0.1) { //what is your logic here for condition x<=20000 ? and x is not reassigning, so it's an infinite loop also. //need only one time output, and so take it out of loop and here, you don't affecting values for amount, rAmount in loop..?? System.out.println(amount); System.out.println(rAmount); } } If it is loan calculator of find total amount remaining to pay after 3 months, then loop runs for 3 times and find percent of amount to pay every month and subtract it from total. int amount = scanner.nextInt(); for( int x=0; x<3; x++) { amount = int ( amount - amount*0.1) ; } System.out.print(amount) ; Hope it helps...
2nd Feb 2022, 9:06 PM
Jayakrishna 🇮🇳
0
You're welcome. Hope you understood it, not just copy-paste.
3rd Feb 2022, 9:23 PM
Qais Hweidi