import java.util.Scanner;

public class BooleanProduct {
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int n = 10;     
        int[][] A = new int[n][n];
        int[][] B = new int[n][n];
        //Fill A and B
      int m,n2,p,q;
        System.out.println("Enter number of rows for matrix A : ");
        m = input.nextInt();
        System.out.println("Enter number of columns for matrix A : ");
        n2 = input.nextInt();
        System.out.println("Enter number of rows for matrix B : ");
        p = input.nextInt();
        System.out.println("Enter number of columns for matrix B : ");
        q = input.nextInt();
        System.out.println("Enter elements for matrix A (by rows): ");
        for (int i=0 ; i < m ; i++)
        for(int j=0 ; j < n2 ; j++)
        {
        A[i][j] = input.nextInt();
        }
        System.out.println("Enter elements for matrix B : ");
        for (int i=0 ; i < p ; i++)
        for(int j=0 ; j < q ; j++){
        B[i][j] = input.nextInt();
        }
        System.out.println("Matrix A: ");
        for(int i=0 ; i < m ; i++)
        {
        System.out.println();
        for(int j=0 ; j < n2 ; j++)
        {
        System.out.print(A[i][j]+" ");
        }
        }
        System.out.println();
        System.out.println("Matrix B: ");
        for (int i=0 ; i < p ; i++)
        { System.out.println();
        for(int j=0 ; j < q ; j++){
        System.out.print(B[i][j]+" ");
        }
        }
        System.out.println();
        }

        int[][] C = booleanProduct(A,B, n);
        {
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                System.out.print(C[i][j] + " ");
            }
            System.out.println("");
        }
    }
    static int[][] booleanProduct(int[][] A, int[][] B, int n) {
        int[][] C = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int[] tmp = new int[n];
                for (int k = 0; k < n; k++) {
                    tmp[k] = product(A[i][k] , B[k][j]);
                }
                C[i][j] = sum(tmp);
            }
        }
        return C;
    }
    static int product (int a, int b) {
        return (a*b == 0) ? 0 : 1;
    }
    static int sum(int[] arr) {
        for (int item : arr) 
            if (item == 1)
                return 1;
        return 0;
    }
}

this is my error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at BooleanProduct.main(BooleanProduct.java:4)
my errors:
Multiple markers at this line
    - B cannot be resolved to a (ln51)
     variable
    - n cannot be resolved to a (ln53)
     variable
    - A cannot be resolved to a (ln54)
     variable

basically: you have a closing bracket for the main method in the middle of the method. so a lot of code that has to be in a method, is floating freely in the class.

Edited 2 Years Ago by stultuske

Can you please be more specific. can you tell me where this closing bracket is?

no, since your editor probably has a different line nr than mine.
just put it in a text file, and apply proper indentation, like this:

class ClassName{ // open class level

       public static void main(String[] args){ // open method
             System.out.println("statement level");       

       } // end of method level

}  // end of class-level

if you do that, it's quite easy to spot

This article has been dead for over six months. Start a new discussion instead.