Skip to main content
Fix indentation
Source Link
Tomer Shetah
  • 8.6k
  • 7
  • 31
  • 40

public class FindSumEquals {

public class FindSumEquals {  public static void main(String[] args) {   int n = 15;   System.out.println("Count is "+ findPossible(n));  }  private static int findPossible(int n) {   int temp = n;   int arrayLength = n / 2 + 2;   System.out.println("arrayLength : " + arrayLength) ;   int a [] = new int[arrayLength];   int count = 0;   for(int i = 1; i < arrayLength; i++){   a[i] = i + a[i - 1];   }   int lower = 0, upper = 1;   while(upper <= arrayLength - 1) {   if(a[upper] - a[lower] == temp) {   System.out.println("hello - > " + ++lower + " to "+ upper);   upper++;   count++;   } else if(a[upper] - a[lower] > temp) {   lower++;   } else {   upper++;   }   }   return count; } } 

}

public class FindSumEquals {

public static void main(String[] args) { int n = 15; System.out.println("Count is "+ findPossible(n)); } private static int findPossible(int n) { int temp = n; int arrayLength = n / 2 + 2; System.out.println("arrayLength : " + arrayLength) ; int a [] = new int[arrayLength]; int count = 0; for(int i = 1; i < arrayLength; i++){ a[i] = i + a[i - 1]; } int lower = 0, upper = 1; while(upper <= arrayLength - 1) { if(a[upper] - a[lower] == temp) { System.out.println("hello - > " + ++lower + " to "+ upper); upper++; count++; } else if(a[upper] - a[lower] > temp) { lower++; } else { upper++; } } return count; } 

}

public class FindSumEquals {  public static void main(String[] args) {   int n = 15;   System.out.println("Count is "+ findPossible(n));  }  private static int findPossible(int n) {   int temp = n;   int arrayLength = n / 2 + 2;   System.out.println("arrayLength : " + arrayLength) ;   int a [] = new int[arrayLength];   int count = 0;   for(int i = 1; i < arrayLength; i++){   a[i] = i + a[i - 1];   }   int lower = 0, upper = 1;   while(upper <= arrayLength - 1) {   if(a[upper] - a[lower] == temp) {   System.out.println("hello - > " + ++lower + " to "+ upper);   upper++;   count++;   } else if(a[upper] - a[lower] > temp) {   lower++;   } else {   upper++;   }   }   return count; } } 
Source Link

public class FindSumEquals {

public static void main(String[] args) { int n = 15; System.out.println("Count is "+ findPossible(n)); } private static int findPossible(int n) { int temp = n; int arrayLength = n / 2 + 2; System.out.println("arrayLength : " + arrayLength) ; int a [] = new int[arrayLength]; int count = 0; for(int i = 1; i < arrayLength; i++){ a[i] = i + a[i - 1]; } int lower = 0, upper = 1; while(upper <= arrayLength - 1) { if(a[upper] - a[lower] == temp) { System.out.println("hello - > " + ++lower + " to "+ upper); upper++; count++; } else if(a[upper] - a[lower] > temp) { lower++; } else { upper++; } } return count; } 

}