
/*
Online Java - IDE, Code Editor, Compiler

Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/

public class Main
{
    public static void main(String[] args) {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        
        int[] numbers = new int[]{20,303,3,4,25};
        int k=3;
        int sumAllNumbers=49;
        Sumnumbers sn = new Sumnumbers(numbers,k,49);
    }
}


class Sumnumbers
{
   
    private int[] numbers;
    private int totalNumbers;
    private int total = 0;
    //private int sumAllNumbers;
    private int []storeKNumbers = new int[3];
    private int m=0;
    
    
    public Sumnumbers(int [] numbers, int totalNumbers, int sumAllNumbers)
    {
        
        this.numbers=numbers;
        this.totalNumbers=totalNumbers;
        //this.sumAllNumbers;
         System.out.println("total numbers is:" + totalNumbers);
         
        for (int i=0; i<numbers.length;i++)
        {
            storeKNumbers[0]=0;
            storeKNumbers[1]=0;
            storeKNumbers[2]=0;
            
            total=0;                    // this sets total to 0
            total = total + numbers[i]; // this sets the first element in the array as total
            
            //if (m>totalNumbers)  //this ensures that if the sum has not been fulfilled in m attempts, it is reset to 0
            //{
                m=0;
            //}
            
            storeKNumbers[m]=numbers[i];    // this will store first of m numbers (3 in this case) as first element.
            m++;  //this will hold counter for number elements placed in array
            System.out.println("value of m is:" + m);
            
            
            for (int j=0;j<numbers.length;j++)
            {
                if (j==1)   // this will ensure that same elements are not added
                {
                    j++;
                    System.out.println("this should print 5 times");
                }
                
                
                if (j>numbers.length)  // this will ensure that elements do not exceed length 
                {
                    
                    continue;
                }
                
                
                    storeKNumbers[m]=numbers[j];  //This will store elements two and three into the array
                    total = total + numbers[j];  // this will check if the total is equal to  sumAllNumbers
                
                }
                
                 
                  //this will hold counter for number elements placed in array
                m++;
                System.out.println("further value of m:" + m);
                
                
                
                
                
            }
        }
    }
        
}
