我有一个程序要求用户输入true或false,然后将输入放入5x3数组中。我必须使用方法,打印区域,然后制作另一种方法来反转它,然后另一种方法打印反转。
到目前为止,这是我的代码:
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( "" );
}
}
}
我一直能够提出问题并将答案放在第一个阵列中并打印出来,但我似乎无法理解如何将其反转。
我的错误是:
/TrueFalse.java:46: error: cannot find symbol
pArray[r][c] = !answ;
^
symbol: variable answ
location: class TrueFalse
1 error