+ 1
What is wrong here? Can not proceed further [JAVA]
Hello, colleagues! I completed Loam Calculator JAVA Challenge, but I can't proceed, as Code Analyzer showing message that I got a bug there. However 2 Test Cases passed, and output completely identical. There are 3 test cases that are hidden, may be something wrong there? Below 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(); //your code goes here int term = 3; for (int i = 1; i <= term; i++ ) { int payment = amount / 100 * 10; amount = amount - payment; } System.out.println(amount); } } Please help, I'm stuck :((
5 odpowiedzi
+ 1
Try to use a double value in calculations.
Try this.
amount -=(amount/100.0 *10)
In loop..
its equivalent to
for (int i = 1; i <= term; i++ ) {
double payment = amount / 100.0 * 10;
amount = (int)(amount - payment);
}
+ 3
Thank you for the answer. But in task description asked to use Integers for amounts
+ 2
Игорь Воронин
You can use integer also but you need to change your calculation logic like:
for(int a = 1; a<=term; a++){
amount = amount - amount * 10 / 100;
}
System.out.println(amount)
You are first dividing amount by 100 so issue is there.
To understand problem see below problem:
System.out.println (90 / 100 * 10); //0
System.out.println (90 * 10 / 100); //9
both will give different result
0
Yes. Amount is of integer but in calculations for interest, if you use a double value then it won't miss praction part. Later you can convert back to int and display as I given above. Not changed the amount type but used a double type in calculations..
Check it once and reply if wrong..
Hope it helps...
0
Question im 11 and how does a variable work