Java program to calculate the simple interest Using 'Scanner' Class

Calculate the Simple Interest

The data needed to calculate simple interest can be initialized with the default value inside the class and also can be taken from the user. Here 'Scanner' class, the built-in class inside the 'util' package of 'java' project is imported to get value from the keyboard.

import java.util.Scanner//Calling Scanner class to read input from Keyboard

public class SimpleInterest
{

     public static void main(String []args)
    {
         //Declaring Variables
         double Principal;
         double Time;
         double Rate;
         double Interest;

         System.out.println("Enter amount of Principle"); //Instruction for User
         Principal= new Scanner(System.in).nextDouble()//Getting value for Principal from user

         System.out.println("Enter Time period"); //Instruction for User
         Time= new Scanner(System.in).nextDouble()//Getting value of Time from user

         System.out.println("Enter Rate of Interest"); //Instruction for User
         Rate= new Scanner(System.in).nextDouble()//Getting Interest Rate from user

         Interest= (Principal*Time*Rate)/100; //Processing
         System.out.println("Simple Interest =  "+Interest); //Printing Result
    }
}

Output:
     Enter amount of Principle
     1500
     Enter Time period
     2.5
     Enter Rate of Interest
     15.1
     
     Simple Interest =  566.25

Comments

Popular posts from this blog

Java Program to make a comparison between numbers

Java program using Scanner Class

Java program to print 'Hello World'