public class Main
{
    public static void main(String []args){
    int k = 17;
    int[] nums = new int[]{10,15,3,7};
    int total=0;
    int i;
    int j;
    
    for (i=0; i<nums.length; i++)
    {
        //This is ok
        //Now need another loop to complete addition
        
        for (j=0; j<nums.length; j++)
        {
            if (j==i )  // do not want to compare number at same each index with each other...
            {
                j++;   //move to next number...
                
            }
            
            if (j!=nums.length)  //if j has not reached last element...
                                 // we need this line because j has been incremented above
                                 //let's say before increment it was processing.. 
                                 //nums[j] where j was 3   =nums[3] = 7
                                 //it can be seen that this is the last element...
                                 //if it started processing  nums[4]  where j=4
                                 //There is no element present here and will give ArrayIndexOutOfBoundsException exception...
            {
                total = nums[i] + nums[j];  //storing all totals...
                System.out.println(nums[i] + "+" + nums[j] +"=" + total);  //displaying output....
                
                if (total==k)
                {
                    //informing end user of correct total....
                    System.out.println("Total is 17: " + nums[i] + "+" + nums[j] + "=" + total+"\n");
                    
                }
                
            }  //end of if loop (if index of j nested for loop has not reached end...)
            
        }  //end of inner for loop
        
    }  //end of outer for loop
        
    }  //end of main
    
}   //end of class