[PROBLEM SOLVED] loan calculator | Sololearn: Learn to code for FREE!

0

[PROBLEM SOLVED] loan calculator

i wrote this code for the 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(); //your code goes here for(int i=0 ; i<3 ; i++){ int payment= ((amount*10)/100); int remaining = amount - payment ; System.out.println(payment); System.out.println(remaining); amount = remaining ; } } } the code is correct and even the expected outputs turn out correct but the website doesnt accept the code ! any idea why ?

3/28/2021 12:16:52 AM

Yasamin Bayrami

23 Answers

New Answer

+18

It would be good to check results in expected output. I mean you can compare your output with the expected output. You need to get output outside for loop to avoid getting several amounts. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int remaining = amount ; //your code goes here for(int i=0 ; i<3 ; i++){ int payment= ((amount*10)/100); remaining = amount - payment ; //System.out.println(payment); amount = remaining ; } System.out.println(remaining); } }

+6

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); } }

+5

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!

+4

Simba it WORKED . thank you!

+3

Jamie Hershberger the letter i is just a random name of an integer variable. You can use any name you want for that. for(int Jamie = 0 ; Jamie<months ; Jamie++)

+2

Here is my answer: import java.util.Scanner; public class Programm{ public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int amount=scanner.nextInt(); int remaining=amount; for(int i=0;i<3;i++){ //System.out.println("Month number: "+i); int toPay=(amount*10)/100; remaining=amount-toPay; //System.out.println(toPay); amount=remaining; } System.out.println(remaining); } }

+2

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 i=0;i<3;i++){ amount-=(amount*0.1); } System.out.println(amount); } }

+1

Isn't it better ? Without loop ?it is working fine. Why I need to use loop here ??? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here int amount1 = amount * 90/100; int amount2 = amount1 * 90/100; int amount3 = amount2 * 90/100; System.out.println(amount3); } }

+1

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=1 ; i<=3 ; i++){ int payment= ((amount*10)/100); amount -= payment ; } System.out.println(amount); } }

+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; for (int i = 1; i <= 3; i++) { loan = amount / 10; amount -= loan; } System.out.println(amount); } }

0

Loan Calculator problem This is right code for this problem my both case got right 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 i=0;i <3; i++){ int payment = ((amount*10)/100); int remaning = amount - payment ; amount = remaning; System.out.println(amount); } } This is is giving both conditions true if you don't want to use loop then u can repeat the condition 3 time by writing them and at last conditon you can print amout that is last answer. If you guys want that program also msg me i will upload that also for you.... By:- ∆√@¥ ♥ Kūmb#à®

0

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 loan; for(int i=1;i<=3;i++) { loan =amount/10; amount-=loan; } System.out.println(amount); } }

0

SIMPLIEST SOLUTION 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 i=0;i<3;i++) { amount-=amount/10; } System.out.println(amount); } }

0

for (int i=0 ; i<1 ; i++){ int payment= ((amount*10)/100); int remaining= amount - payment; //System.out.println(payment); //System.out.println(remaining); amount=remaining; } {int payment= ((amount*10)/100); int remaining= amount - payment; //System.out.println(payment); //System.out.println(remaining); amount=remaining;} int payment= ((amount*10)/100); int remaining= amount - payment; //System.out.println(payment); System.out.println(remaining); amount=remaining; simple layout in 3 steps

0

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; int ramount = amount ; for(int i=0;i<=2;i++){ payment=(10*amount)/100; ramount=amount-payment; amount = ramount; } System.out.println(ramount); } }

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 months = 3; for(int i=0 ; i<months ; i++) amount = (amount*90/100); System.out.println(amount); } } this is the right code for calculating loan

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 = 1; x<=3; x++){ int payment = ((amount*10)/100); int remaining = amount - payment; amount = remaining; } System.out.println(amount); } }

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); } }

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 i = 0 ;i < 3 ; i++ ){ int payment = ((amount*10) /100); amount -= payment; } System.out.println(amount); } }