Please help with my code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Please help with my code

I'm taking a java course, for finish it is necessary to make a loan calculator, I have three tests well but 2 don't, this is my code. 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 x=0; x<6; ++x){ amount =(amount -(10*amount)/100); } System.out.println(amount-1); } }

23rd Feb 2021, 5:08 PM
Camilo Andrés Egas
Camilo Andrés Egas - avatar
2 Answers
+ 1
I could find the solution 😁. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //tu código va aquí int aux; for(int i=1;i<=6;i++){ aux = amount/10; if(amount%10!=0){ aux++; } amount = amount - aux; } System.out.println(amount); } }
23rd Feb 2021, 5:22 PM
Camilo Andrés Egas
Camilo Andrés Egas - avatar
+ 3
My solution was similar to Martin Taylor: for(int i=0; i<6; i++) { amount *= 0.9; }
23rd Feb 2021, 6:29 PM
Paul K Sadler
Paul K Sadler - avatar