

InterviewSolution
1. |
Write a program to input/assign the values of principal p, rate r and time t, and display the simple interest and amount at the end of the given time period |
Answer» tion:SIMPLE Interest - JavaWe need to first take User Input for the values of Principal Amount (P), Rate of Interest (R) and Time PERIOD (T). We will do this by using Scanner.We store them as double type values. Then, we calculate the Simple Interest using the formula and display it.\rule{300}{1}import java.util.Scanner; //Importing Scannerpublic class SimpleInterest //Creating Class{ public static void main(String[] ARGS) //The main function { Scanner scr = new Scanner(System.in); //Creating Scanner Object //Take User Input for P, R and T System.out.print("Enter Principal Amount (P): "); double P = scr.nextDouble(); System.out.print("Enter Rate of Interest (R): "); double R = scr.nextDouble(); System.out.print("Enter Time Period (T): "); double T = scr.nextDouble(); //Calculate Simple Interest I = (PRT)/100 double I = (P*R*T)/100; //Display the Simple Interest System.out.println("Simple Interest = "+I); }} |
|