ICSE Class 10 Computer Applications
Question 17 of 32
Input in Java — Question 17
Back to all questions 17
Question Question 17
Write a program in Java that takes input using the Scanner class to calculate the Simple Interest and the Compound Interest with the given values:
i. Principle Amount = Rs.1,00,000
ii. Rate = 11.5%
iii. Time = 5 years
Display the following output:
i. Simple interest
ii. Compound interest
iii. Absolute value of the difference between the simple and compound interest.
import java.util.Scanner;
public class KboatInterest
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Principal: ");
double p = in.nextDouble();
System.out.print("Enter Rate: ");
double r = in.nextDouble();
System.out.print("Enter Time: ");
int t = in.nextInt();
double si = p * r * t / 100.0;
double cAmt = (p * Math.pow(1 + (r / 100), t));
double ci = cAmt - p;
double diff = Math.abs(si - ci);
System.out.println("Simple interest = " + si);
System.out.println("Compound interest = " + ci);
System.out.println("Absolute Difference = " + diff);
in.close();
}
}Output
