Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FuncionesRelaciones;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author phd
- */
- public class test {
- public static void cPotencia(int num) {
- for (int i = 0; i < Math.pow(2, num); i++) {
- int[] array = new int[num];
- int temp = i;
- for (int j = 0; j < array.length; j++) {
- array[j] = temp % 2;
- temp /= 2;
- }
- String res = "{";
- for (int k = 0; k < array.length; k++) {
- if (array[k] == 1) {
- res += (k + 1) + ",";
- }
- }
- res += "}, ";
- System.out.print(res);
- }
- System.out.println();
- }
- public static void main(String[] args) {
- cPotencia(5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement