Write a java program to find sum of digits of a number. Given an input number, we have to write a java code to calculate sum of digits of a number.

For example –

i)

Input : 256

Output : 13 (2+5+60

ii)

Input : 15

Output : 6 (1+5)

Technology Blog Where You Find Programming Tips and Tricks

Write a java program to find sum of digits of a number. Given an input number, we have to write a java code to calculate sum of digits of a number.

For example –

i)

Input : 256

Output : 13 (2+5+60

ii)

Input : 15

Output : 6 (1+5)

Given a decimal number, Write a java program to convert decimal to binary number.

For example :

Input : 4 , Output : 100

Input : 5 , Output : 101

Input : 10 , Output : 1010

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

Write a java program to find second smallest number in an array. Given an input array, write a java code to print second smallest number of an array.

For example :

arr = {-1, 7, 1, 34, 18}

The second smallest number in this array is 1.