0
Java loan calculator
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. 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=amount; for(int i=0;i<3;i++){ int payment= (90/100); remain*=payment; } System.out.println(remain); } } //why is my code dont give any output?, what is wrong
10 Respostas
+ 3
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 k = amount;
int persent;
int payment;
for (int i = 0 ; i < 3; i++) {
persent = k * 10 /100;
payment = k - persent;
k = payment;
}
System.out.println(k);
}
}
you must understand about algorithms,
by nuari ananda
+ 3
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 x = 0;x < 3;x++) {
amount -= ((amount * 10) / 100);
};
System.out.println(amount);
}
}
//Simple
+ 1
Jack Van Hoeven
remain = 0.1 * remain
amount - =remain
+ 1
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
int loan;
//your code goes here
for(int i=1;i<=3;i++)
{
loan =amount/10;
amount-=loan;
}
System.out.println(amount);
}
}
0
You need to calculate 10% of the current amount and subtract that 10% from the current amount for each iteration of the loop. Also, if there is a fractional part (part after the decimal) you will need to round the percent up to the next whole number before subtracting from the current amount.
0
thanks for help
I got the answer from google but I still dont understand why I cant directly multiples the amount(100000) with 90/100,
this is the correct answer
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
int remain = amount;
for (int i = 0 ; i <3; i++) {
int payment = (int)Math.ceil(10/100.0*remain);
remain -= payment;
}
System.out.println(remain);
}
}
0
Working 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 payment = 0;
int month = 1;
do{
if (amount%10 == 0){
payment = amount/10;
amount = amount - payment;
}
else {
payment = amount/10 +1;
amount = amount - payment;
}
month++;
} while (month <= 3);
System.out.println(amount);
}
}
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
for(int x=3; x!=0; x--){
amount *= 0.9;
} System.out.println(amount);
}
}
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 payment , remainingAmount;
for(int i=0; i<3; i++ )
{
payment=(10/100)*amount;
remainingAmount=amount-payment;
System.out.println(remainingAmount);
}
}
}
- 1
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 pay;
for(int i = 0; i < 3; i++)
{
pay = (10*amount)/100;
amount -= pay;
}
System.out.println(amount);
}
}