basically i am taking a number 759 and turning it into 648 . Each digit of the number is decresed by -1 . i am using a STACK . CAN I DO IT WITHOUT STACK . like i when you flip a number , you can do it using a simple varible .
import java.util.Stack;
public class A {
public static void main(String[] args) {
int n = 234;
int output = 0;
Stack <Integer> stack = new Stack<>();
while (n!=0)
{
int lastdigit = n%10;
n = n/10;
stack.push(lastdigit-1);
}
while (!stack.isEmpty())
{
output = (output*10) + stack.peek();
stack.pop();
}
System.out.println(output);
}
}