这里的总体目标是创建一个使用参数的方法,其中包括一个数组和一个基于用户选择的整数。我希望它按顺序打印一个5x5数组,然后如果用户做出相反的决定。
我很难调用这个方法来测试第一部分是否正常工作。
这里是我所拥有的:
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
public class arrayPrinter
//printer method meant to print the 2d array normally
public static void printarray (int iarray[][], int entry )
{
if ( entry == 0 )
{
for ( int iarrprint [] : iarray )
{
System.out.println ( Arrays.toString (iarrprint));
}
}
else
{
}
return;
}
//main method
public static void main (String args[])
{
//5 by 5 array created
int iarray [][] = new int [5][5];
// array populated with random numbers between 1 and 100
for (int irow = 0; irow < iarray.length; irow++)
{
for (int icol = 0; icol < iarray[irow].length; icol++)
{
Random rnum = new Random();
int igen = Math.abs(rnum.nextInt (100));
iarray [irow][icol] = igen;
}
}
Scanner sc = new Scanner (System.in);
System.out.println ( "Print array in order? Press 0 / Print the array in reverse? Press 1" );
int testvalue = sc.nextInt();
printarray ( iarray[][], testvalue ); //error .class expected
}我希望能够更好地使用数组,但是我会被一些琐碎的东西所吸引。
我得到了.class预期的错误。
任何建议都会很好。
发布于 2014-02-02 08:24:09
按以下方式调用该方法:
printarray ( iarray, testvalue ); // you don't need [][] herehttps://stackoverflow.com/questions/21501335
复制相似问题