Created
June 6, 2017 19:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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