title: java - how to reduce execution time for this program
body: <pre><code>int n, k;
  int count = 0, diff;
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  String[] input;
  input = br.readLine().split(" ");
  n = Integer.parseInt(input[0]);
  int[] a = new int[n];
  k = Integer.parseInt(input[1]);
  input = br.readLine().split(" ");
  for (int i = 0; i &lt; n; i++) {
    a[i] = Integer.parseInt(input[i]);
       for (int j = 0; j &lt; i; j++) {
          diff = a[j] - a[i];
          if (diff == k || -diff == k) {
             count++;
          }
       }
  }
  System.out.print(count);
  </code></pre>
  
  <p>This is a sample program where I am printing particular difference count, where n range is &lt;=100000
  Now problem is to decrease execution for this program. How can I make it better to reduce running time.</p>
  
  <p>Thanks in advance for suggestions</p>