0

What am i doing wrong?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int remain=amount; int months = 1; for(months=1; months<=6; months++){ int paid = (remain/10); remain=remain-paid; System.out.println(remain); } } }

6th Dec 2020, 2:58 PM
IOANNIS KERMIZIDIS
IOANNIS KERMIZIDIS - avatar
2 Réponses
0
The output got 5 correct results and the 6th instead is 1 greater ...for example instead of 53144 i get 53145 as 6th result!
6th Dec 2020, 3:00 PM
IOANNIS KERMIZIDIS
IOANNIS KERMIZIDIS - avatar
0
You should get fraction part in remain/10 and round up value. For if : remain/10.0 = 12.1 then use 13 value.
6th Dec 2020, 9:01 PM
Jayakrishna 🇮🇳