Advertisement
ArCiGo

Conjunto Potencia (a)

Apr 5th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package FuncionesRelaciones;
  2.  
  3. /*
  4.  * To change this template, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. /**
  8.  *
  9.  * @author phd
  10.  */
  11. public class test {
  12.  
  13.     public static void cPotencia(int num) {
  14.         for (int i = 0; i < Math.pow(2, num); i++) {
  15.             int[] array = new int[num];
  16.             int temp = i;
  17.             for (int j = 0; j < array.length; j++) {
  18.                 array[j] = temp % 2;
  19.                 temp /= 2;
  20.             }
  21.             String res = "{";
  22.             for (int k = 0; k < array.length; k++) {
  23.                 if (array[k] == 1) {
  24.                     res += (k + 1) + ",";
  25.                 }
  26.             }
  27.             res += "}, ";
  28.             System.out.print(res);
  29.         }
  30.         System.out.println();
  31.     }
  32.  
  33.     public static void main(String[] args) {
  34.  
  35.         cPotencia(5);
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement