Java programs

Let’s learn swap three variables in java without temporary variable. Swap three variables in java without using temporary variable In the below example we are using arithmetic operators to swap three variables without temporary variable. public class SwapThreeNumbersWithoutTemp { static int num1, num2, num3; public static void main(String[] args) { num1 = 30; num2 =…

Read More Swap three variables in java without temporary variable

Let’s learn to add two matrices in java using bufferedreader. Add two matrices in java using bufferedreader Here’s addition of two matrices using bufferedreader. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class AddTwoMatrixUsingBufferedReader { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int a, b; int[][] arr1 =…

Read More Add two matrices in java using bufferedreader

Let’s learn java program to calculate average of 3 numbers. Java program to calculate average of 3 numbers In program to calculate average of 3 numbers first get input from user using nextDouble() method of Scanner class and storing in three variables number1, number2 and number3. These variables are then passed to calculateAverage() method to…

Read More Java program to calculate average of 3 numbers

Let’s learn reverse an array without using another array in java. Reverse an array without using another array in java To reverse an array without using another array we are using for loop which loops till middle index of given array and then swap first number with the last number, swap second number with second…

Read More Reverse an array without using another array in java

Let’s learn reverse a string in java without using reverse function. Reverse a string in java without using reverse function Here are ways to reverse a string without using reverse function. One using for loop, while loop, and recursion. Here’s the program to reverse a string using for loop without using reverse method. for loop…

Read More Reverse a string in java without using reverse function

Let’s learn java program to calculate compound interest. Java program to calculate compound interest To calculate compound interest here’s the formula. P (1 + R/n) (nt) – P In compound interest formula, P – is principal amount. R – is annual interest rate. t – is time the money invested or borrowed. n – number…

Read More Java program to calculate compound interest

Let’s learn multiplication table in java using array. Multiplication table in java using array Here’s the java code for multiplication table using two dimensional array and nested for loop. public class MultiplicationTableUsingArray { public static void main(String[] args) { int[][] arrMultipleTable = new int[10][10]; int row = 1, column = 1; for(int a = 0;…

Read More Multiplication table in java using array