0

I have an a program that asks the user to enter true or false and then it puts the input in a 5x3 array. I have to then, using methods, print the area, then make another method to invert it, then another to print the invert.

This is my code so far:

import java.util .*;
public class TrueFalse
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{

    boolean myA[][] = new boolean [5][3];

    popArray(myA);
    printA(myA);
    flip(myA);
    printB(myA);
}

public static void popArray(boolean pArray[][])
{
   System.out.println("Enter true or false.");
   boolean answ = console.nextBoolean();
    for (int r=0; r < pArray.length; ++r)
        {
         for (int c=0; c < pArray[0].length; ++c)
            {   
            pArray[r][c] = answ;
            }       
        }
}
 public static void printA(boolean pArray[][])
     {
       for (int i = 0; i < pArray.length; i++) 
        {
            for (int c=0; c<pArray[0].length; c++)
            {
            System.out.print(pArray[i][c] + " ");
            }
             System.out.println( "" );
        }
     }
  public static void flip(boolean pArray[][])
       {

            for (int r=0; r < pArray.length; ++r)
                {
                 for (int c=0; c < pArray[0].length; ++c)
                    {   
                    pArray[r][c] = !answ;
                    }       
      }
}
public static void printB(boolean pArray[][])
         {
           for (int i = 0; i < pArray.length; i++) 
            {
                for (int c=0; c<pArray[0].length; c++)
                {
                System.out.print(pArray[i][c] + " ");
                }
                 System.out.println( "" );
            }
     }
}  

I keep was able to get ask the question and put the answer in the first array and print it but I can't seem to quite get how to invert it.

My error is:

/TrueFalse.java:46: error: cannot find symbol
                    pArray[r][c] = !answ;
                                    ^
  symbol:   variable answ
  location: class TrueFalse
1 error
Richard Chambers
  • 16,643
  • 4
  • 81
  • 106

0 Answers0