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)
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)
Write a java code to check balanced parentheses in an expression using stack.
Given an expression containing characters ‘{‘,’}’,'(‘,’)’,'[‘,’]’. We have to write a code to check whether an input string has valid parentheses.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Example –
i) {[]}) – Invalid
ii) {()}[] – Valid
Write a java program to reverse a string using stack data structure. Given an input string, We have to write a java code to reverse a string using stack.
In my previous tutorial, I have explained java program to reverse a string using recursion.
Before solving this problem, Let’s understand what is a stack data structure.