Java recursion code -


public class temp {     public static void main(string[] args) {         system.out.println(recursion(1, 100));         system.out.println(recursion(4, 5));         system.out.println(recursion(99, 100));         system.out.println(recursion(100, 100));     }      public static int recursion(int m, int n) {         int number = 0;         if (m == 1) {             number = ((2 * n) - 1);         } else {             number = 2 * recursion(m - 1, n - 1);         }         return number;     } } 

when run code, last 2 tests return 0's , know supposed big numbers, why? how can figure out value of last two??

you're running arithmetic overflow. int can store values between -2^31 , 2^31-1. deal numbers big, need more suitable data type, such biginteger.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -