#Help With Math formula in JAVA (EASY) .

1 messages · Page 1 of 1 (latest)

cosmic blade
#

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);

}
}

main domeBOT
#

This post has been reserved for your question.

Hey @cosmic blade! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

main domeBOT