fork download
  1. /* package whatever; // count no of pairs in ana array that sum up to given k elementt */
  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[] a={1,2,3,4,5};
  13. int b=5;
  14. //String b="god";
  15. int tt=pair(a,b);
  16. // int[][] matrix = {
  17. // {1, 2, 3},
  18. // {4, 5, 6},
  19. //{7, 8, 9}
  20. //};
  21. System.out.println((tt));
  22. //swap(a,b);
  23. }
  24.  
  25. public static int pair(int[] arr,int k){
  26. int count=0;
  27. for(int i=0;i<arr.length;i++){
  28. for(int j=i+1;j<arr.length;j++){
  29. if(arr[i]+arr[j]==k){
  30. count++;
  31. }
  32. }
  33. }
  34. return count;
  35. }
  36. }
Success #stdin #stdout 0.09s 54500KB
stdin
Standard input is empty
stdout
2