What's wrong in this program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's wrong in this program?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int initialAmount = scanner.nextInt(); //your code goes here int remainingAmount = initialAmount; int months = 0; for(months = 0; months <= 5; months++){ int payment = (remainingAmount * 10) /100; remainingAmount = remainingAmount - payment; } System.out.println(remainingAmount ); } }

17th Apr 2021, 11:35 AM
Sandeep
Sandeep - avatar
8 Answers
+ 1
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int initialAmount = scanner.nextInt(); //your code goes here int remainingAmount = initialAmount; int months = 0; for(months = 0; months <3; months++){ int payment = (remainingAmount * 10) /100; remainingAmount = remainingAmount - payment; } System.out.println(remainingAmount ); } }
17th Apr 2021, 11:48 AM
Atul [Inactive]
+ 1
You have to calculate it for 3 months
17th Apr 2021, 11:48 AM
Atul [Inactive]
+ 1
Use this for(months = 0; months <= 2; months++){ because we only have to calculate for 3 months See here: "You take a loan from a friend and need to calculate how much you will owe him after 3 months."
17th Apr 2021, 11:55 AM
Coding Cat
Coding Cat - avatar
+ 1
I think so the question is changed after the update. If you update your app and read the question again you will get to know that it is written 3 months
17th Apr 2021, 12:26 PM
Atul [Inactive]
0
I tried a lot of times but I couldn't find what's the mistake
17th Apr 2021, 11:37 AM
Sandeep
Sandeep - avatar
0
Why we have to take 3 months
17th Apr 2021, 11:50 AM
Sandeep
Sandeep - avatar
0
Sandeep Kumar Just do this for (months = 0; months <= 5; months++) { initialAmount = initialAmount * 90 / 100; } System.out.println(initialAmount);
17th Apr 2021, 2:22 PM
A͢J
A͢J - avatar
0
Got the output TQ u guys for helping me
17th Apr 2021, 7:44 PM
Sandeep
Sandeep - avatar