How can i solve the second project in java lessons?🙄 i tried hard to solve it 😕 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

How can i solve the second project in java lessons?🙄 i tried hard to solve it 😕

The problem is about (You take a loan from a friend and need to calculate how much you will owe him after 6 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 6 months.)

13th Jan 2021, 8:06 PM
Ahmad Hseen
Ahmad Hseen - avatar
12 Answers
+ 2
Same problem was in my code.Its all about your answere.For exaple expected number was 112233 but you have 112233,6 so with the rounding it was coverted to 112234.That is the problem.Change int to double in your code and you will see what im talking about
13th Jan 2021, 9:16 PM
Владислав Кадыгроб
Владислав Кадыгроб - avatar
+ 2
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); for(int i=0;i<3;i++) { int payment; payment = amount/10; amount -= payment; } System.out.print(amount); } }
9th May 2021, 9:46 AM
Priyadharshan S
+ 1
That what i mean I need a little help This 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 for(int i=0;i<6;i++) {int payment; payment =amount*/10; amount-=payment;} System.out.print(amount); } }
13th Jan 2021, 8:18 PM
Ahmad Hseen
Ahmad Hseen - avatar
0
can you attatch your code so we can have a look. also we can’t tell you the solution but we can point you in the right direction!
13th Jan 2021, 8:14 PM
Brian R
Brian R - avatar
0
You probably wanted to write payment = amount / 10; instead of payment = amount */ 10; What's more, I'm not sure, but shouldn't the variables "amount" and "payment" be double instead of int?
13th Jan 2021, 9:07 PM
Lukáš Vladař
13th Jan 2021, 9:09 PM
Владислав Кадыгроб
Владислав Кадыгроб - avatar
0
I noticed that and i fix it But not this the problem My result was close to the expected result by a difference of 1
13th Jan 2021, 9:12 PM
Ahmad Hseen
Ahmad Hseen - avatar
0
Yes you are right It's work I forget this idea Thanks
13th Jan 2021, 9:25 PM
Ahmad Hseen
Ahmad Hseen - avatar
0
You are welcome,good luck!
13th Jan 2021, 9:28 PM
Владислав Кадыгроб
Владислав Кадыгроб - avatar
0
Right
15th Jan 2021, 3:36 PM
Ramna Ramna
Ramna Ramna - 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(); for(int i=0;i<3;i++) { int payment; payment = amount/10; amount -= payment; } System.out.print(amount); } }
9th May 2021, 9:36 AM
Priyadharshan S
0
here is the solution 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 for(int month = 1; month <= 3; month++) { amount -= amount/10; } System.out.println(amount); } }
5th Sep 2021, 4:14 AM
KADEK ROMI ARDANA PUTRA
KADEK ROMI ARDANA PUTRA - avatar