Skip to content

Instantly share code, notes, and snippets.

@Blasanka
Created June 6, 2017 19:55
Show Gist options
  • Save Blasanka/700912f398335fd240de36589fc70a09 to your computer and use it in GitHub Desktop.
Save Blasanka/700912f398335fd240de36589fc70a09 to your computer and use it in GitHub Desktop.
This is a simple program created for get combinations for any given number set. Note: efficience wise this is not hundred persent good.
import java.util.ArrayList;
import java.util.List;
public class Combinations {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
int[] a = {0,1,2};//change values as many you want
for(int i: a){
list.add(i+"");//add first numbers in array- 1,2,3
}
for(int times = 0; times < a.length; times++){
String first = a[times]+"";
for(int i = 0; i< a.length; i++){
String temp = first + i;
list.add(temp);//add to arraylist
}
}
for(String s: list){
System.out.print(s + " ");
}
}
}
/*---------------Output---------------------------
output: 0 1 2 00 01 02 10 11 12 20 21 22
------------------------------------------------*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment