title: how can i get elements from array which makes sum equals to given value
body: <p>how can i find lowest number of integers in the array that sums up the given number. The program should ask user to input array of integers (“Input Array”) and the required sum (“Required Sum”). The output (“Output”) should list the lowest number of integers from the input array that sums up the “Required Sum”.</p>
  
  <p>here i create the <em>function sum()</em> and declare array with some elements when read sum from user <strong>45</strong> it gives me output <strong>25,25</strong> but when i input <strong>59</strong> and <strong>60</strong> nothing shows on output</p>
  
  <pre><code> public static void sum()
  {
  
  
  int arr[]={10,0,-1,20,25,30};
  Scanner in=new Scanner(System.in);
  int sum=in.nextInt();
  
  int[] sub = new int[arr.length];
  int temp = 0;
          for (int i = 0; i &lt; arr.length; i++)
          {
              for (int j = i, col = 0; j &lt; arr.length; j++, col++)
              {
                  //add the value of input array one by one
                  temp += arr[j];
                  sub[col] = arr[j];
                     //if addition is equal to sum then print it
                   if (temp == sum)
                  {
                    int total = 0;
                     for (int k = 0; k &lt; sub.length; k++)
                    {
                            total += sub[k];
                         System.out.println(sub[k]);
  
                         //if total and sum are equal then leave the print
                          if (total == sum)
                          {
                                 System.out.println();
                              break;
                          }
                       }
                  }
                  //if temp is greater than sum are equal then clear the sub array, set temp value and leave the loop for next
                 if (temp &gt; sum)
                  {
                      temp = 0;
                     break;
                  }
              }
          }
  
  }
  </code></pre>
  
  <p>Output Example:</p>
  
  <p><strong>Input Array :</strong> <code>[10, 0, -1, 20, 25, 30]</code></p>
  
  <p><strong>Required Sum:</strong> <code>45</code>
  <strong>Output:</strong> <code>[20, 25]</code></p>
  
  <p><strong>Required Sum:</strong> <code>59</code>
  <strong>Output:</strong> <code>[10, -1, 20, 30]</code></p>
  
  <p><strong>Required Sum:</strong> <code>60</code>
  <strong>Output:</strong> <code>[10, 20, 30]</code></p>