0

What's wrong with my code in one of the projects in java?

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; int remainingAmount=0; for(int month=1; month<=6; month++) { payment = amount/10; remainingAmount = amount - payment; amount = remainingAmount; } System.out.println(amount); } }

10th Jan 2021, 6:18 PM
Radhakrishan
Radhakrishan - avatar
1 Odpowiedź
+ 3
Radhakrishan 1 - Take amout as double 2 - use Math.ceil inside loop 3 - cast double value to int to get output double amount = scanner.nextDouble(); for (int i = 1; i <= 6; i++) { amount = amount - Math.ceil(amount / 10); } System.out.println((int) amount);
10th Jan 2021, 6:22 PM
A͢J
A͢J - avatar