mercredi 7 mars 2018

Getting Summations and storing in an arraylist

I need some help on this program. The goal is to calculate all the summations possible to add to a particular number. For example, getSummations(5) would return "1+4", "2+3". This is because no numbers can be repeated in the summation. It cannot be "2+2+1". Also, summations can include more than two numbers. For example "1 +2 +9" is a value that needs to be returned for getSummations(12). Any suggestions on where to start would be greatly appreciated.

import java.util.ArrayList;

public class Problem6 {

public static void main(String[] args) {

    System.out.println(getSummations(5));
    System.out.println(getSummations(8));
    System.out.println(getSummations(12));
}

public static ArrayList<String> getSummations(int n) {
    // Replace null with answer
    return null;
}

}

Aucun commentaire:

Enregistrer un commentaire