Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

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

Java Programs
  • Math.pow() is used for power calculation
  • Math.abs() ensures the difference is always positive