Advertisement
enissay

Recursivity error !

Jan 13th, 2016
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Testing {
  2.    
  3.     private static int limit = 10_000;
  4.  
  5.     public static void main(String[] args) {
  6.         long sum = 0;
  7.        
  8.         // Iterative calculus of sum up to limit
  9.         for (int i = 0; i < limit; i++) {
  10.             if( i%(limit/10) == 0 ) {
  11.                 System.out.println("i = " + i);
  12.             }
  13.             sum += i;
  14.         }
  15.  
  16.         System.out.println("sum = " + sum);
  17.        
  18.         System.out.println("++++++");
  19.  
  20.         // Recursive calculus of sum up to limit
  21.         recursivity(0, limit);
  22.     }
  23.  
  24.     private static void recursivity(int sum, int currVal) {
  25.         --currVal;
  26.        
  27.         if( currVal%(limit/10) == 0 ) {
  28.             System.out.println("limit = " + currVal);
  29.         }
  30.        
  31.         if ( currVal == 0) {
  32.             System.out.println("sum = " + sum);
  33.         }
  34.         else {
  35.             sum += currVal;
  36.             recursivity(sum, currVal);
  37.         }
  38.        
  39.     }
  40. }
Advertisement
RAW Paste Data Copied
Advertisement