Here you will learn about pascal triangle in java with a program example. What is Pascal’s Triangle? It is a triangular array of the binomial coefficients. It is a number pattern which starts with 1 at top and then placing numbers below it in triangular pattern. Each number is obtained by adding two numbers above …
Here you will learn about java private constructor. What is private constructor in Java? We can make a constructor private by using private access modifier. Private constructor prevents the instantiation of class from outside. If needed we can create the instance only inside the class. Where to use Java private constructor? We can use private …
Here you will get java program to check even or odd number. How to check? If number is completely divisible by 2 then it is even otherwise odd. In our program we will find the remainder of number by dividing it by 2 using modulus (%) operator. If remainder is 0 then number is even …
Here you will get program to convert decimal to binary in Java. Below I have shared 3 different methods for java decimal to binary conversion. Also Read: Convert Binary to Decimal in Java Convert Decimal to Binary in Java 1. Integer.toString() Method We can convert a decimal number to binary using toString() method of Integer class. …
Here you will get java program to calculate compound interest. We can calculate compound interest by following formula. Compound Interest = Principle * (1 + Rate / 100) time Also Read: Java Program to Calculate Simple Interest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
importjava.util.Scanner;
publicclassJavaCompoundInterest{
publicstaticvoidmain(Stringargs[]){
doublep,r,t,ci;
Scanner sc=newScanner(System.in);
System.out.print("Enter principle: ");
p=sc.nextDouble();
System.out.print("Enter rate: ");
r=sc.nextDouble();
System.out.print("Enter time: ");
t=sc.nextDouble();
ci=p*(Math.pow(1+(r/100),t));
System.out.print("\nCompound Interest = "+ci);
}
}
Output Enter principle: 1000 Enter rate: 4 Enter time: 10 Compound Interest = 1480.2442849183444
Here you will get java program to swap numbers using temporary variable. It can be done in following way. temp = a a = b b = temp Also Read: Java Program to Swap Two Numbers Without Using Third Variable
Here you will get java program to swap two numbers without using third variable or temporary variable. We can do this in 3 ways as mentioned below. Also Read: Java Program to Swap Two Numbers Using Temporary Variable 1. Using Addition & Subtraction Operator We can swap two numbers using addition (+) and subtraction (-) …