-2

int ans = Integer.MAX_VALUE -(-1); //should I explicitly cast my method parameters in calculation to a wider bit type ?

Ricko
  • 5
  • 1
  • 5
  • 1
    Does this answer your question? [How can I check if multiplying two numbers in Java will cause an overflow?](https://stackoverflow.com/questions/1657834/how-can-i-check-if-multiplying-two-numbers-in-java-will-cause-an-overflow) – DekuDesu May 16 '21 at 17:39

1 Answers1

0

Found a solution on searching the internet. An article that may help learners like me. https://www.drdobbs.com/jvm/signalling-integer-overflows-in-java/210500001

Ricko
  • 5
  • 1
  • 5
  • another source with great solutions for the question https://wiki.sei.cmu.edu/confluence/display/java/NUM00-J.+Detect+or+prevent+integer+overflow – Ricko May 16 '21 at 07:36