Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static java.lang.reflect.Array.set;
- import java.util.ArrayList;
- public class Kolikot {
- private ArrayList <Integer> kolikot;
- public Kolikot() {
- this.kolikot = new ArrayList<>();
- }
- public void lisaaKolikko(int arvo) {
- this.kolikot.add(arvo);
- }
- public int laskeYhdistelmat(int summa) {
- ArrayList <Boolean> booleanTaulukko = new ArrayList<>();
- ArrayList <Integer> taulukko = new ArrayList<>();
- int maara = 0;
- int pituus = this.kolikot.size();
- for (int i = 0; i < (1 << pituus); i++) { //i < 16
- int summakaksi = 0;
- for(int j = 0; j < pituus; j++) {
- if ((i & (1 << j)) > 0) {
- taulukko.add(this.kolikot.get(j));
- summakaksi += this.kolikot.get(j);
- }
- }
- if (summakaksi == summa) {
- booleanTaulukko.add(true);
- }
- }
- return booleanTaulukko.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement