0

Need help what to code to get the 10% of the amount

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.

14th Feb 2022, 6:26 AM
Renz Malayan Cole
Renz Malayan Cole - avatar
4 Respostas
+ 4
Renz Malayan Cole I would suggest you create a variable, make it a double as it will need to handle decimals. Then you apply the math for calculating a tip, amount * 0.1 which will give you an answer, but also include a lot of unwanted decimals. So we want to round out the answer. A quick google search returns Math.round() with an explanation on how to get the desired number of decimal places. I hope this snippet helps explain further //your code goes here double tip = Math.round(amount * 0.1 *10); tip /= 10; System.out.println(tip); } }
14th Feb 2022, 8:45 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Renz Malayan Cole Do you have a code concept to post with your question? It helps us identify where you are struggling
14th Feb 2022, 6:42 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Rik Wittkopp you mean these? 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 } }
14th Feb 2022, 6:48 AM
Renz Malayan Cole
Renz Malayan Cole - avatar
+ 2
//your code goes here Good Luck int x=1; while(x<=3) { amount -= amount * 0.1; x++; } System.out.println(amount);
14th Feb 2022, 7:23 AM
SoloProg
SoloProg - avatar