fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int []arr={1,3,4,5,8};
  13. int n=arr.length;
  14. int l=0,e=n-1,k=5,c=0;
  15. while(l < e){
  16. if(arr[l]+arr[e] > k){
  17. c+=(e-l+1)-1;
  18. System.out.println(c +"l==>"+l+"e==>"+e);
  19. e--;
  20. }
  21. else{
  22. l++;
  23. }
  24. }
  25. }
  26. }
Success #stdin #stdout 0.13s 55684KB
stdin
Standard input is empty
stdout
4l==>0e==>4
7l==>0e==>3
8l==>1e==>2