Java Program to Print 1 to 100 Numbers without using Loop

Write a java program to print 1 to 100 numbers without using loop.  This problem is very interesting and tricky for beginners. You have to think how you can print numbers from 1 to 100 without using for and while loop in your code.

We can easily solved this problem using loop (for and while loop).  But suppose you don’t have to use loop to print the numbers.

Implement Queue using Two Stacks – Java Code & Algorithm

How to implement a queue using two stacks. In this tutorial, I am going to discuss how to implement a first in first out (FIFO) queue using only two stacks.

In this problem, we are going to implement following methods of QueueUsingStack class:

void push(int x) – Insert an element x.
int pop() –  Removes the element (In FIFO order).
int peek() – Returns the element which is present at the front of the queue.
boolean empty() – Returns true if no element is present else false.

For example –

Find Common Elements in Three Sorted Arrays – Java Code

Write a java program to find common elements in three sorted arrays.

Given three sorted arrays, write a code to print intersection of three sorted arrays.

For example –

arr1 = {1, 5, 10, 20, 40, 80};
arr2 = {6, 7, 20, 80, 100};
arr3 = {3, 4, 15, 20, 30, 70, 80, 120};

Output : {20, 80}

20 and 80 are the common elements in 3 arrays. These two elements are the intersection of 3 sorted arrays.