fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static int numLinha;
  11.  
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. int dims = 5;
  15. int size = 3;
  16. numLinha = 0;
  17. getMatrix(dims, size);
  18. }
  19.  
  20. private static void getMatrix(int dims, int size) {
  21. int[] arr = new int[dims];
  22. getMatrixPoint(0, 0, dims, arr, size);
  23. }
  24.  
  25. private static void getMatrixPoint(int pos, int index, int currDim, int[] arr, int size) {
  26.  
  27. //condicao de fim de recursao
  28. if (currDim == 0) {
  29. String strPoint = "(";
  30. String sep = "";
  31. for (int i = 0; i < arr.length; i++) {
  32. strPoint = strPoint + sep + arr[i];
  33. sep = ", ";
  34. }
  35. strPoint = strPoint + ")";
  36. System.out.println(++numLinha + " - " + strPoint);
  37. return;
  38. }
  39.  
  40. //para cada possivel valor da primeira dimensao
  41. //calcule os possiveis pontos da (quantidade_de_dimensoes - 1)
  42. for (int i = 0; i < size; i++) {
  43. arr[pos] = i;
  44. getMatrixPoint(pos + 1, i, currDim - 1, arr, size);
  45. arr[pos] = 0;
  46. }
  47. }
  48. }
Success #stdin #stdout 0.06s 4386816KB
stdin
Standard input is empty
stdout
1 - (0, 0, 0, 0, 0)
2 - (0, 0, 0, 0, 1)
3 - (0, 0, 0, 0, 2)
4 - (0, 0, 0, 1, 0)
5 - (0, 0, 0, 1, 1)
6 - (0, 0, 0, 1, 2)
7 - (0, 0, 0, 2, 0)
8 - (0, 0, 0, 2, 1)
9 - (0, 0, 0, 2, 2)
10 - (0, 0, 1, 0, 0)
11 - (0, 0, 1, 0, 1)
12 - (0, 0, 1, 0, 2)
13 - (0, 0, 1, 1, 0)
14 - (0, 0, 1, 1, 1)
15 - (0, 0, 1, 1, 2)
16 - (0, 0, 1, 2, 0)
17 - (0, 0, 1, 2, 1)
18 - (0, 0, 1, 2, 2)
19 - (0, 0, 2, 0, 0)
20 - (0, 0, 2, 0, 1)
21 - (0, 0, 2, 0, 2)
22 - (0, 0, 2, 1, 0)
23 - (0, 0, 2, 1, 1)
24 - (0, 0, 2, 1, 2)
25 - (0, 0, 2, 2, 0)
26 - (0, 0, 2, 2, 1)
27 - (0, 0, 2, 2, 2)
28 - (0, 1, 0, 0, 0)
29 - (0, 1, 0, 0, 1)
30 - (0, 1, 0, 0, 2)
31 - (0, 1, 0, 1, 0)
32 - (0, 1, 0, 1, 1)
33 - (0, 1, 0, 1, 2)
34 - (0, 1, 0, 2, 0)
35 - (0, 1, 0, 2, 1)
36 - (0, 1, 0, 2, 2)
37 - (0, 1, 1, 0, 0)
38 - (0, 1, 1, 0, 1)
39 - (0, 1, 1, 0, 2)
40 - (0, 1, 1, 1, 0)
41 - (0, 1, 1, 1, 1)
42 - (0, 1, 1, 1, 2)
43 - (0, 1, 1, 2, 0)
44 - (0, 1, 1, 2, 1)
45 - (0, 1, 1, 2, 2)
46 - (0, 1, 2, 0, 0)
47 - (0, 1, 2, 0, 1)
48 - (0, 1, 2, 0, 2)
49 - (0, 1, 2, 1, 0)
50 - (0, 1, 2, 1, 1)
51 - (0, 1, 2, 1, 2)
52 - (0, 1, 2, 2, 0)
53 - (0, 1, 2, 2, 1)
54 - (0, 1, 2, 2, 2)
55 - (0, 2, 0, 0, 0)
56 - (0, 2, 0, 0, 1)
57 - (0, 2, 0, 0, 2)
58 - (0, 2, 0, 1, 0)
59 - (0, 2, 0, 1, 1)
60 - (0, 2, 0, 1, 2)
61 - (0, 2, 0, 2, 0)
62 - (0, 2, 0, 2, 1)
63 - (0, 2, 0, 2, 2)
64 - (0, 2, 1, 0, 0)
65 - (0, 2, 1, 0, 1)
66 - (0, 2, 1, 0, 2)
67 - (0, 2, 1, 1, 0)
68 - (0, 2, 1, 1, 1)
69 - (0, 2, 1, 1, 2)
70 - (0, 2, 1, 2, 0)
71 - (0, 2, 1, 2, 1)
72 - (0, 2, 1, 2, 2)
73 - (0, 2, 2, 0, 0)
74 - (0, 2, 2, 0, 1)
75 - (0, 2, 2, 0, 2)
76 - (0, 2, 2, 1, 0)
77 - (0, 2, 2, 1, 1)
78 - (0, 2, 2, 1, 2)
79 - (0, 2, 2, 2, 0)
80 - (0, 2, 2, 2, 1)
81 - (0, 2, 2, 2, 2)
82 - (1, 0, 0, 0, 0)
83 - (1, 0, 0, 0, 1)
84 - (1, 0, 0, 0, 2)
85 - (1, 0, 0, 1, 0)
86 - (1, 0, 0, 1, 1)
87 - (1, 0, 0, 1, 2)
88 - (1, 0, 0, 2, 0)
89 - (1, 0, 0, 2, 1)
90 - (1, 0, 0, 2, 2)
91 - (1, 0, 1, 0, 0)
92 - (1, 0, 1, 0, 1)
93 - (1, 0, 1, 0, 2)
94 - (1, 0, 1, 1, 0)
95 - (1, 0, 1, 1, 1)
96 - (1, 0, 1, 1, 2)
97 - (1, 0, 1, 2, 0)
98 - (1, 0, 1, 2, 1)
99 - (1, 0, 1, 2, 2)
100 - (1, 0, 2, 0, 0)
101 - (1, 0, 2, 0, 1)
102 - (1, 0, 2, 0, 2)
103 - (1, 0, 2, 1, 0)
104 - (1, 0, 2, 1, 1)
105 - (1, 0, 2, 1, 2)
106 - (1, 0, 2, 2, 0)
107 - (1, 0, 2, 2, 1)
108 - (1, 0, 2, 2, 2)
109 - (1, 1, 0, 0, 0)
110 - (1, 1, 0, 0, 1)
111 - (1, 1, 0, 0, 2)
112 - (1, 1, 0, 1, 0)
113 - (1, 1, 0, 1, 1)
114 - (1, 1, 0, 1, 2)
115 - (1, 1, 0, 2, 0)
116 - (1, 1, 0, 2, 1)
117 - (1, 1, 0, 2, 2)
118 - (1, 1, 1, 0, 0)
119 - (1, 1, 1, 0, 1)
120 - (1, 1, 1, 0, 2)
121 - (1, 1, 1, 1, 0)
122 - (1, 1, 1, 1, 1)
123 - (1, 1, 1, 1, 2)
124 - (1, 1, 1, 2, 0)
125 - (1, 1, 1, 2, 1)
126 - (1, 1, 1, 2, 2)
127 - (1, 1, 2, 0, 0)
128 - (1, 1, 2, 0, 1)
129 - (1, 1, 2, 0, 2)
130 - (1, 1, 2, 1, 0)
131 - (1, 1, 2, 1, 1)
132 - (1, 1, 2, 1, 2)
133 - (1, 1, 2, 2, 0)
134 - (1, 1, 2, 2, 1)
135 - (1, 1, 2, 2, 2)
136 - (1, 2, 0, 0, 0)
137 - (1, 2, 0, 0, 1)
138 - (1, 2, 0, 0, 2)
139 - (1, 2, 0, 1, 0)
140 - (1, 2, 0, 1, 1)
141 - (1, 2, 0, 1, 2)
142 - (1, 2, 0, 2, 0)
143 - (1, 2, 0, 2, 1)
144 - (1, 2, 0, 2, 2)
145 - (1, 2, 1, 0, 0)
146 - (1, 2, 1, 0, 1)
147 - (1, 2, 1, 0, 2)
148 - (1, 2, 1, 1, 0)
149 - (1, 2, 1, 1, 1)
150 - (1, 2, 1, 1, 2)
151 - (1, 2, 1, 2, 0)
152 - (1, 2, 1, 2, 1)
153 - (1, 2, 1, 2, 2)
154 - (1, 2, 2, 0, 0)
155 - (1, 2, 2, 0, 1)
156 - (1, 2, 2, 0, 2)
157 - (1, 2, 2, 1, 0)
158 - (1, 2, 2, 1, 1)
159 - (1, 2, 2, 1, 2)
160 - (1, 2, 2, 2, 0)
161 - (1, 2, 2, 2, 1)
162 - (1, 2, 2, 2, 2)
163 - (2, 0, 0, 0, 0)
164 - (2, 0, 0, 0, 1)
165 - (2, 0, 0, 0, 2)
166 - (2, 0, 0, 1, 0)
167 - (2, 0, 0, 1, 1)
168 - (2, 0, 0, 1, 2)
169 - (2, 0, 0, 2, 0)
170 - (2, 0, 0, 2, 1)
171 - (2, 0, 0, 2, 2)
172 - (2, 0, 1, 0, 0)
173 - (2, 0, 1, 0, 1)
174 - (2, 0, 1, 0, 2)
175 - (2, 0, 1, 1, 0)
176 - (2, 0, 1, 1, 1)
177 - (2, 0, 1, 1, 2)
178 - (2, 0, 1, 2, 0)
179 - (2, 0, 1, 2, 1)
180 - (2, 0, 1, 2, 2)
181 - (2, 0, 2, 0, 0)
182 - (2, 0, 2, 0, 1)
183 - (2, 0, 2, 0, 2)
184 - (2, 0, 2, 1, 0)
185 - (2, 0, 2, 1, 1)
186 - (2, 0, 2, 1, 2)
187 - (2, 0, 2, 2, 0)
188 - (2, 0, 2, 2, 1)
189 - (2, 0, 2, 2, 2)
190 - (2, 1, 0, 0, 0)
191 - (2, 1, 0, 0, 1)
192 - (2, 1, 0, 0, 2)
193 - (2, 1, 0, 1, 0)
194 - (2, 1, 0, 1, 1)
195 - (2, 1, 0, 1, 2)
196 - (2, 1, 0, 2, 0)
197 - (2, 1, 0, 2, 1)
198 - (2, 1, 0, 2, 2)
199 - (2, 1, 1, 0, 0)
200 - (2, 1, 1, 0, 1)
201 - (2, 1, 1, 0, 2)
202 - (2, 1, 1, 1, 0)
203 - (2, 1, 1, 1, 1)
204 - (2, 1, 1, 1, 2)
205 - (2, 1, 1, 2, 0)
206 - (2, 1, 1, 2, 1)
207 - (2, 1, 1, 2, 2)
208 - (2, 1, 2, 0, 0)
209 - (2, 1, 2, 0, 1)
210 - (2, 1, 2, 0, 2)
211 - (2, 1, 2, 1, 0)
212 - (2, 1, 2, 1, 1)
213 - (2, 1, 2, 1, 2)
214 - (2, 1, 2, 2, 0)
215 - (2, 1, 2, 2, 1)
216 - (2, 1, 2, 2, 2)
217 - (2, 2, 0, 0, 0)
218 - (2, 2, 0, 0, 1)
219 - (2, 2, 0, 0, 2)
220 - (2, 2, 0, 1, 0)
221 - (2, 2, 0, 1, 1)
222 - (2, 2, 0, 1, 2)
223 - (2, 2, 0, 2, 0)
224 - (2, 2, 0, 2, 1)
225 - (2, 2, 0, 2, 2)
226 - (2, 2, 1, 0, 0)
227 - (2, 2, 1, 0, 1)
228 - (2, 2, 1, 0, 2)
229 - (2, 2, 1, 1, 0)
230 - (2, 2, 1, 1, 1)
231 - (2, 2, 1, 1, 2)
232 - (2, 2, 1, 2, 0)
233 - (2, 2, 1, 2, 1)
234 - (2, 2, 1, 2, 2)
235 - (2, 2, 2, 0, 0)
236 - (2, 2, 2, 0, 1)
237 - (2, 2, 2, 0, 2)
238 - (2, 2, 2, 1, 0)
239 - (2, 2, 2, 1, 1)
240 - (2, 2, 2, 1, 2)
241 - (2, 2, 2, 2, 0)
242 - (2, 2, 2, 2, 1)
243 - (2, 2, 2, 2, 2)