Move All Zeroes to End of Array – Java Code

Write a java program to move all zeroes to end of array. Given an array of random integers move all zeroes to end of array. The order of all other elements of an array should be same.

In this tutorial, We are going to discuss and write a java program to move zeroes to end of an array. It is another interesting problem which generally asked in a technical interviews.

For example –

Input : {1, 2, 0, 4, 0, 5, 3, 8}

Output: {1, 2, 4, 5, 3, 8, 0, 0}

You can see in the example, we have moved zeroes to the end of an array.

Java Program to Add Two Matrices

Write a java program to add two matrices.

For example : Given two matrices A and B the sum of these two matrices is A + B.

Subscribe Our Tutorials

Get Latest Updates on Facebook

{1,  5,  1}                   {1,  1,  9}              {2,  6,  10}
{2,  8,  2}      +         {2,  2,  3}    =       {4,  10,  5}
{3,  7,  1}                  {5,  6,  4}              {8,  13,  5}

Find Next Greater Element in an Array – Java Code

Write a java program to find next greater element in an array. Given an input array, find the next greater element for every element of an array.The next greater element x is the first greater element on the right side of x in an array.

In this tutorial, I am going to explain two approaches and their time complexities to solve this problem. In the first approach, we’ll see how we can find next greater element using two for loops. And after that we can discuss how we can find next greater element using stack.

Also, I have explained how to find next greater element using stack through video tutorial.

For example:

Let’s take an array: [4, 2, 6, 8, 1]

4 => 6 (First next greater element of 4 is 6)
2 => 6 (Next greater element of 2 is 6)
6 => 8 (Next greater element of 6 is 8)
8 => null
1 => null

Java Program to Reverse a String using Recursion

Write a java program to reverse a string using recursion. In this tutorial, I am going to explain how to write a java code which reverse an input string using recursion. I have also added the video at the end of this tutorial.

For example :

Input String: Object
Output String: tcejbO

Sum of Digits of a Number using Recursion – Java Code

Write a java program to find sum of digits of a number using recursion. Given a number, Write a java code to calculate sum of digits of a number using recursion.

For example –

Input number : 123
Output : 6 (1 + 2 + 3)

In my previous tutorial, I have explained how to find sum of digit of a number using iterative approach. In this tutorial, we are  going to learn how we can do it using recursion.

Find Largest of Three Numbers using Ternary Operator in Java

Write a java program to find largest of three numbers using ternary operator in java. Given a three input numbers, we have to write a java code to print largest of three numbers using ternary operator.

Suppose, if we have three numbers a, b and c. If a is greater than b and c then a is the largest of three numbers. Similarly, if b is greater than a and c then b is the largest of three numbers else c is largest.