title: Return indices of the two numbers such that they add up to a specific target
body: <p>I have the below question I am trying to solve:</p>
  
  <blockquote>
    <p>Given an array of integers, return indices of the two numbers such that they add up to a specific target.</p>
  </blockquote>
  
  <p>I have the below array as input - [2, 7, 11, 15] with target = 9.</p>
  
  <p>Because nums[0] + nums[1] = 2 + 7 = 9,
  return [0, 1].</p>
  
  <p>This is my code -</p>
  
  <pre><code>import java.util.Random;
  
  public class TwoSum {
  
      static int[] numbers = new int[] {2, 7, 11, 15};
      int[] indices = new int[numbers.length];
  
      public static int[] returnIndices(int target, int[] inputArr) {
          int[] indices = new int[2];
          int randomOne = new Random().nextInt(inputArr.length);
          int randomTwo = new Random().nextInt(inputArr.length);
          while(true) {
              if(target == inputArr[randomOne] + inputArr[randomTwo]) {
                  indices[0] = randomOne;
                  indices[1] = randomTwo;
                  break;
              }
          }
          System.out.println("done");
          return indices;
      }
  
      public static void main(String[] args) {
          int[] output = returnIndices(9, numbers);
      }
  
  }
  </code></pre>
  
  <p>Is this the right way to approach my problem? </p>