Write a Java Program to Calculate simple interest and compound interest

Java Program to Calculate simple interest and compound interest

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a Java Program to Calculate simple interest and compound interest

Java Program to Calculate simple interest and compound interest
Java Program to Calculate simple interest and compound interest

PROGRAM: Java Program to Calculate simple interest and compound interest

/*Java Program to Calculate simple interest and compound interest*/

1: Calculate Simple Interest in Java

import java.util.Scanner;

class Main {
public static void main(String[] args) {

// create an object of Scanner class
Scanner input = new Scanner(System.in);

// take input from users
System.out.print(“Enter the principal: “);
double principal = input.nextDouble();

System.out.print(“Enter the rate: “);
double rate = input.nextDouble();

System.out.print(“Enter the time: “);
double time = input.nextDouble();

double interest = (principal * time * rate) / 100;

System.out.println(“Principal: ” + principal);
System.out.println(“Interest Rate: ” + rate);
System.out.println(“Time Duration: ” + time);
System.out.println(“Simple Interest: ” + interest);

input.close();
}
}

2: Calculate Compound Interest

import java.util.Scanner;

class Main {
public static void main(String[] args) {

// create an object of Scanner class
Scanner input = new Scanner(System.in);

// take input from users
System.out.print(“Enter the principal: “);
double principal = input.nextDouble();

System.out.print(“Enter the rate: “);
double rate = input.nextDouble();

System.out.print(“Enter the time: “);
double time = input.nextDouble();

System.out.print(“Enter number of times interest is compounded: “);
int number = input.nextInt();

double interest = principal * (Math.pow((1 + rate/100), (time * number))) – principal;

System.out.println(“Principal: ” + principal);
System.out.println(“Interest Rate: ” + rate);
System.out.println(“Time Duration: ” + time);
System.out.println(“Number of Time interest Compounded: ” + number);
System.out.println(“Compound Interest: ” + interest);

input.close();
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *