Advertisement
ArCiGo

Conjunto Potencia (b)

Apr 5th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package FuncionesRelaciones;
  6.  
  7. import java.util.*;
  8.  
  9. /**
  10.  *
  11.  * @author phd
  12.  */
  13. public class ConjuntoP {
  14.  
  15.     public static void main(String[] args) {
  16.  
  17.         String[] array = {"1", "2", "3", "4"};
  18.         cPotencia(array);
  19.  
  20.     }
  21.  
  22.     public static void cPotencia(String[] array) {
  23.  
  24.         LinkedHashSet obj = new LinkedHashSet();
  25. //        ArrayList some = new ArrayList();
  26.         int sizeArray = (int) Math.pow(2, array.length);
  27.  
  28.         for (int q = 0; q < sizeArray; q++) {
  29.  
  30.             String str = Integer.toBinaryString(q);
  31.             int val = str.length();
  32.             String aux = str;
  33.  
  34.             for (int r = val; r < array.length; r++) {
  35.                 aux = "0" + aux;
  36.             }
  37.  
  38.             LinkedHashSet obje = new LinkedHashSet();
  39.  
  40. //            System.out.println(obj);
  41.  
  42.             for (int s = 0; s < aux.length(); s++) {
  43.                 if (aux.charAt(s) == '1') {
  44.                     obje.add(array[s]);
  45.                 }
  46.             }
  47.             obj.add(obje);
  48. //            some.add(objII.toString());
  49.         }
  50. //        Collections.sort(some);
  51. //        for (int i = 0; i < some.size(); i++) {
  52. //            System.out.print(some.get(i)+", ");
  53. //        }
  54. //        Arrays[] holis=(Arrays[]) obj.toArray();
  55. //        Object holis []= obj.toArray();
  56. //        System.out.println(holis.length);
  57. //        for (int i = 0; i < holis.length; i++) {
  58. //            System.out.print(holis[i]+", ");
  59. //            
  60. //        }
  61. //        Arrays.sort(holis);
  62. //        Arrays.sort(holis);
  63.         System.out.println(obj.toString().replace("[", "{").replace("]", "}"));
  64. //      System.out.println(Arrays.toString(holis));
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement