Soluții

Java Program to Calculate Compound Interest

Compound interest is calculated using the following formula:

P (1 + R/n) (nt) - P

Here P is principal amount.
R is the annual interest rate.
t is the time the money is invested or borrowed for.
n is the number of times that interest is compounded per unit t, for example if interest is compounded monthly and t is in years then the value of n would be 12. If interest is compounded quarterly and t is in years then the value of n would be 4.

Before writing the java program let’s take an example to calculate the compound interest. Let’s say an amount of $2,000 is deposited into a bank account as a fixed deposit at an annual interest rate of 8%, compounded monthly, the compound interest after 5 years would be:

P = 2000.
R = 8/100 = 0.08 (decimal).
n = 12.
t = 5.

Let’s put these values in the formula.

Compound Interest = 2000 (1 + 0.08 / 12) (12 * 5) – 2000 = $979.69

So, the compound interest after 5 years is $979.69.

[mai mult...]

Java Program to check Vowel or Consonant using Switch Case

The alphabets A, E, I, O and U (smallcase and uppercase) are known as Vowels and rest of the alphabets are known as consonants. Here we will write a java program that checks whether the input character is vowel or Consonant using switch case in java.

In this program we are not using break statement with cases intentionally, so that if user enters any vowel, the program continues to execute all the subsequent cases until Case 'U' is reached and thats where we are setting up the value of a boolean variable to true. This way we can identify that the alphabet entered by user is vowel or not.

[mai mult...]

Java Program to check Leap Year

Before we see the program, lets see how to determine whether a year is a leap year mathematically:
To determine whether a year is a leap year, follow these steps:
1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
4. The year is a leap year (it has 366 days).
5. The year is not a leap year (it has 365 days).

[mai mult...]