- 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.)
12 ответов
+ 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
+ 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);
}
}
+ 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);
}
}
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!
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?
0
You are welcome.
https://code.sololearn.com/cqcbm6xPa90J/?ref=app
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
0
Yes you are right
It's work
I forget this idea
Thanks
0
You are welcome,good luck!
0
Right
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);
}
}
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);
}
}