0

I have passed the first two test cases in my exercise, but the other three ones gives error.

I have passed the first two test cases in my exercise, but the other three ones gives error and I can't see why they giving error because they are locked. And anybody couldn't solve that. The community section of that exercise is empty.Please help me with this issue I don't want the full solution. 20. CODE PROJECT You take a loan from a friend and need to calculate how much you will owe him after 3 months. You are going to pay him back 10% of the remaining loan amount each month. Create a program that takes the loan amount as input, calculates and outputs the remaining amount after 3 months. Sample Input: 20000 Sample Output: 10628 Here is the monthly payment schedule: Month 1 Payment: 10% of 20000 = 2000 Remaining amount: 18000 Month 2 Payment: 10% of 18000 = 1800 Remaining amount: 16200 Month 3: Payment: 10% of 16200 = 1620 Remaining amount: 14580

5th Nov 2021, 8:16 AM
Talat Kamas
10 ответов
+ 2
You may find some hints if you searched the forum for similar questions, many had asked questions around this challenge.
5th Nov 2021, 8:26 AM
Ipang
+ 2
Well you can make it a bit simpler Considering that the payment is 10% So the remaining amount would be 90% right? So you can say 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 remain; for(int x=3;x>0;x--) { amount*=0.9; // System.out.println(amount); } System.out.println(amount); } } try it and if there is still an error i will retry
5th Nov 2021, 8:44 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 2
It worked thank you :) I never have tried to look from that side :)
5th Nov 2021, 9:06 AM
Talat Kamas
+ 2
Your welcome good luck :)
5th Nov 2021, 9:07 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 2
You can i will try to explain it as well as i can When one value is an int and the other is a double, Java creates a new temporary value that is the double version of the int value So java supports mixing differnt types of operands as long as they are from the same category i mean int double short long etc You can read about it here for wider understanding https://www.cs.umd.edu/~clin/MoreJava/Intro/expr-mixed.html
5th Nov 2021, 9:22 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
the test cases are hidden so that you can think of a way to improve your code and understand where an error may happen If you can add your code so that we can find a way to improve it or to guess what test case may cause the fail
5th Nov 2021, 8:36 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
You can also write *90/100 here you are dealing with int without the need for java to change the operand to a double that is what i know ,you may find a flow in my knowledge though
5th Nov 2021, 9:25 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
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 remain; for(int x=3;x>0;x--) { remain=amount/100*10; amount=amount-remain; // System.out.println(amount); } System.out.println(amount); } } My code is here. Please help me.
5th Nov 2021, 8:38 AM
Talat Kamas
0
I will ask another thing: we multiply the amount with 0.9 its okay. But the variable type of amount is int and 0.9 is double am i wrong ? How the IDE can multiply int with double variable type ?
5th Nov 2021, 9:14 AM
Talat Kamas
0
Thank you it helped a lot
5th Nov 2021, 9:34 AM
Talat Kamas