In this program, we are going to share reverse a number using stack with the output. If you are a Java beginner and want to start learning the Java programming, then keep your close attention in this tutorial as I am going to share how to write reverse a number using the stack.
Copy the below Java program and execute it with the help of Javac compiler. At the end of this program, We have shared the output of this program.
public class ReverseNumberProgram
static void push_digits(int number)
while(number != 0)
st.push(number % 10);
number = number / 10;
static int reverse_number(int number)
int reverse = 0;
int i = 1;
reverse = reverse + (st.peek() * i);
i = i * 10;
public static void main(String args)
int number = 987654321;
Liked this program? Do Like & share with your friends 🙂
Tags: algorithm to reverse a string using stack, How to reverse a number using stack, java program to reverse a number using stack, reverse a number using stack in java, reverse stack using two stacks, String reversal using stack, Write a java program to reverse, Write a program to reverse a number in Java