标签:style blog color os java io for ar div
1 package interview; 2 3 import java.util.LinkedList; 4 import java.util.List; 5 6 public class ABCDE { 7 8 private boolean ab(boolean a, boolean b){ 9 if(a && !b) return false; 10 return true; 11 } 12 13 private boolean bc(boolean b, boolean c){ 14 if(b && c) return false; 15 if(!b && !c) return false; 16 return true; 17 } 18 19 private boolean cd(boolean c, boolean d){ 20 if(c && !d) return false; 21 if(!c && d) return false; 22 return true; 23 } 24 25 private boolean de(boolean d, boolean e){ 26 if(!d && !e) return false; 27 return true; 28 } 29 30 private boolean ead(boolean e, boolean a, boolean d){ 31 if(e){ 32 if(!a) return false; 33 if(!d) return false; 34 } 35 return true; 36 } 37 38 public boolean trueCondition(boolean a, boolean b, boolean c, boolean d, boolean e){ 39 if(ab(a, b) && bc(b, c) && cd(c, d) && de(d, e) && ead(e, a, d)) return true; 40 return false; 41 } 42 43 public boolean trueCondition(List<Boolean> booleans){ 44 boolean a, b, c, d, e; 45 a = booleans.get(0); 46 b = booleans.get(1); 47 c = booleans.get(2); 48 d = booleans.get(3); 49 e = booleans.get(4); 50 return trueCondition(a, b, c, d, e); 51 } 52 53 public static List<Boolean> intToBooleanBit(int aInt, int size) { 54 if (aInt < 0) throw new IllegalArgumentException(); 55 String bitString = "00000" + Integer.toBinaryString(aInt); 56 bitString = bitString.substring(bitString.length() - size); 57 List<Boolean> booleanList = new LinkedList<Boolean>(); 58 for (int i = 0; i < bitString.length(); i++) { 59 booleanList.add(new Boolean(bitString.charAt(i) == ‘0‘ ? false : true)); 60 } 61 return booleanList; 62 } 63 64 public static void main(String[] args){ 65 ABCDE instance = new ABCDE(); 66 int pass = 32; 67 int size = 5; 68 for(int i=0; i<pass; i++){ 69 List<Boolean> booleanList = intToBooleanBit(i, 5); 70 if(booleanList.size() != 5){ 71 System.out.println("bit list size error!"); 72 System.exit(-1); 73 }else{ 74 if(instance.trueCondition(booleanList)){ 75 System.out.println(booleanList.toString()); 76 } 77 } 78 } 79 } 80 }
标签:style blog color os java io for ar div
原文地址:http://www.cnblogs.com/dadad/p/ABCDE.html