Java programs

Let’s learn to swap three variables in java without using 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 using temporary variable. public class SwapThreeNumbersWithoutTemp { static int num1, num2, num3; public static void main(String[] args) { num1 =…

Read More swap three variables in java without using 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 find average of 3 numbers in java we are taking input from user using nextDouble() method of Scanner class and storing in three variables number1, number2 and number3. These variables are then passed to…

Read More Java program to calculate average of 3 numbers

Let’s learn to 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…

Read More Reverse an array without using another array in java

Let’s learn to reverse a string in java without using reverse function. Reverse a string in java without using reverse function We can reverse a string without using reverse function using for loop, while loop, and recursion. Here’s the program to reverse a string using for loop without using reverse method. for loop loops until…

Read More Reverse a string in java without using reverse function