Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package FuncionesRelaciones;
- import java.util.*;
- /**
- *
- * @author phd
- */
- public class ConjuntoP {
- public static void main(String[] args) {
- String[] array = {"1", "2", "3", "4"};
- cPotencia(array);
- }
- public static void cPotencia(String[] array) {
- LinkedHashSet obj = new LinkedHashSet();
- // ArrayList some = new ArrayList();
- int sizeArray = (int) Math.pow(2, array.length);
- for (int q = 0; q < sizeArray; q++) {
- String str = Integer.toBinaryString(q);
- int val = str.length();
- String aux = str;
- for (int r = val; r < array.length; r++) {
- aux = "0" + aux;
- }
- LinkedHashSet obje = new LinkedHashSet();
- // System.out.println(obj);
- for (int s = 0; s < aux.length(); s++) {
- if (aux.charAt(s) == '1') {
- obje.add(array[s]);
- }
- }
- obj.add(obje);
- // some.add(objII.toString());
- }
- // Collections.sort(some);
- // for (int i = 0; i < some.size(); i++) {
- // System.out.print(some.get(i)+", ");
- // }
- // Arrays[] holis=(Arrays[]) obj.toArray();
- // Object holis []= obj.toArray();
- // System.out.println(holis.length);
- // for (int i = 0; i < holis.length; i++) {
- // System.out.print(holis[i]+", ");
- //
- // }
- // Arrays.sort(holis);
- // Arrays.sort(holis);
- System.out.println(obj.toString().replace("[", "{").replace("]", "}"));
- // System.out.println(Arrays.toString(holis));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement