December 10, 2011
|
By Prasanna Sherekar |
Java Example to Calculate Simple Interest
Simple Interest = (P × R × T) / 100
P — Principal amount
R — rate per annum
T — time in years
Java method to calculate simple interest with given p, r and t values.
public double getSimpleInterest ( int p , double r , int t ) {
double simpleInterest = ( p * r * t ) / 100 ;
return simpleInterest ;
}
December 5, 2011
|
By Prasanna Sherekar |
Java Example to Calculate Compound Interest
Compound Interest = P (1 + R/n) (nt) – P
P — the principal investment amount (the initial deposit or loan amount)
r — the annual interest rate (decimal)
n — the number of times that interest is compounded per unit t
t — the time the money is invested or borrowed for
Java method to calculate compound interest with given P, t, r and n values.
public double getCompoundInterest ( int p , int t , double r , int n ) {
double amount = p * Math . pow ( 1 + ( r / n ) , n * t ) ;
double compundInterest = amount - p ;
return compundInterest ;
}
December 1, 2011
|
By Prasanna Sherekar |
Check if given Year is a Leap Year in Java
Java method to check whether given year is a leap year or not
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public boolean isLeapYear ( int year ) {
boolean isLeap = false ;
if ( year % 4 == 0 ) {
if ( year % 100 == 0 ) {
if ( year % 400 == 0 ) {
isLeap = true ;
} else {
isLeap = false ;
}
} else {
isLeap = true ;
}
} else {
isLeap = false ;
}
return isLeap ;
}