Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class QuineMcCluskey {
- static boolean isZero = false;
- static int num = 0;
- static String[][] binaryArr;
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter Number of Numbers");
- num = sc.nextInt();
- System.out.println("Enter Numbers");
- binaryArr = new String[num * 16][5];
- int hold = 0;
- int hold2 = 0;
- int badtest = 0;
- for (int i = 0; i < num; i++) {
- badtest = sc.nextInt();
- binaryArr[i][2] = Integer.toString(badtest) + ",";
- binaryArr[i][3] = " ";
- binaryArr[i][4] = "0";
- if (badtest == 0)
- isZero = true;
- binaryArr[i][0] = Integer.toBinaryString(badtest);
- for (int j = 0; j < binaryArr[i][0].length(); j++) {
- hold += Character.getNumericValue(binaryArr[i][0].charAt(j));
- binaryArr[i][1] = String.valueOf(hold);
- }
- hold2 = 16 - binaryArr[i][0].length(); // <---- num of bits
- for (int k = 0; k <= hold2; k++) {
- binaryArr[i][0] = "0" + binaryArr[i][0];
- }
- hold = 0;
- hold2 = 0;
- }
- for (int i = num; i < binaryArr.length; i++) {
- binaryArr[i][0] = "000000000000000000";
- binaryArr[i][1] = "000000000000000000";
- binaryArr[i][2] = "000000000000000000";
- binaryArr[i][3] = " ";
- binaryArr[i][4] = "0";
- }
- compare();
- sc.close();
- for (int i = 0; i < num; i++) {
- System.out.print(binaryArr[i][0] + " ");
- System.out.printf("%6s", binaryArr[i][1]);
- System.out.printf("%16s", binaryArr[i][2]);
- System.out.print(" " + binaryArr[i][3] + " " + binaryArr[i][4] + "\n");
- }
- }
- private static void compare() {
- int size = binaryArr.length;
- int check = 0;
- int stuff = 0;
- int internalnum = num;
- int iteration = 0;
- StringBuilder holdString = new StringBuilder("00000000000000000");
- for (int i = 0; i < size - 1; i++) {
- for (int k = i; k < internalnum; k++) {
- check = 0;
- stuff = 0;
- if (Integer.valueOf(binaryArr[k][4]) == iteration
- && Integer.valueOf(binaryArr[i][1]) < Integer.valueOf(binaryArr[k][1])) {
- for (int j = 0; j <= 16; j++) {
- if (binaryArr[i][0].charAt(j) != binaryArr[k][0].charAt(j)) {
- check++;
- holdString.replace(0, 17, binaryArr[i][0]);
- holdString.setCharAt(j, '-');
- }
- }
- for (int m = 0; m <= 16; m++) {
- if (holdString.charAt(m) == '1')
- stuff++;
- }
- }
- if (check == 1) {
- internalnum++;
- binaryArr[i][3] = "c";
- binaryArr[k][3] = "c";
- binaryArr[internalnum - 1][0] = holdString.toString();
- binaryArr[internalnum - 1][1] = String.valueOf(stuff);
- binaryArr[internalnum - 1][2] = binaryArr[i][2] + binaryArr[k][2];
- binaryArr[internalnum - 1][4] = Integer.toString(iteration + 1);
- check = 0;
- stuff = 0;
- if (internalnum > 55) {
- internalnum--;
- }
- }
- }
- if (Integer.valueOf(binaryArr[i][4]) < Integer.valueOf(binaryArr[i + 1][4]))
- iteration++;
- }
- num = internalnum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement