- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Input in Java
Chapter 6
Input in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Simple Interest & Compound Interest Calculation
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 InterestCalculation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input values
System.out.print("Enter Principal Amount: ");
double principal = sc.nextDouble();
System.out.print("Enter Rate of Interest (%): ");
double rate = sc.nextDouble();
System.out.print("Enter Time (in years): ");
double time = sc.nextDouble();
// Simple Interest calculation
double simpleInterest = (principal * rate * time) / 100;
// Compound Interest calculation
double amount = principal * Math.pow((1 + rate / 100), time);
double compoundInterest = amount - principal;
// Absolute difference
double difference = Math.abs(simpleInterest - compoundInterest);
// Display results
System.out.println("\n--- Interest Details ---");
System.out.println("Simple Interest = Rs. " + simpleInterest);
System.out.println("Compound Interest = Rs. " + compoundInterest);
System.out.println("Absolute Difference = Rs. " + difference);
sc.close();
}
}
Output
SAMPLE INPUT : Enter Principal Amount: 100000 Enter Rate of Interest (%): 11.5 Enter Time (in years): 5 SAMPLE OUTPUT : --- Interest Details --- Simple Interest = Rs. 57500.0 Compound Interest = Rs. 72356.55 Absolute Difference = Rs. 14856.55
Explanation
- Math.pow() is used for power calculation
- Math.abs() ensures the difference is always positive
