Java 示例课程代码未编译

Java 示例课程代码未编译,java,variables,methods,Java,Variables,Methods,您好,我有一个作业,它告诉我运行下面的java代码, 但我不断得到3个类似的错误,比如变量studentInfo不能解析为变量 这里是错误 错误:无法将studentInfo解析为变量-第11行 错误:无法将studentInfo解析为变量-第15行 错误:无法将studentInfo解析为变量-第15行 public class DisplayInfoExersice { public static void main( String [ ] args ) {

您好,我有一个作业,它告诉我运行下面的java代码, 但我不断得到3个类似的错误,比如变量studentInfo不能解析为变量

这里是错误

错误:无法将studentInfo解析为变量-第11行 错误:无法将studentInfo解析为变量-第15行 错误:无法将studentInfo解析为变量-第15行

    public class DisplayInfoExersice {

        public static void main( String [ ] args ) {

             int studentInfo [ ] [ ] = { {1, 78, 85}, {2, 83, 90} };

             display( studentInfo );
        }

        public static void display( int array [ ] [ ] ) {

             for ( int j = 0; j < studentInfo.length; j++ ) {

                 System.out.println( ); 

                 for ( int k = 0; k < studentInfo[j].length; k++)
                       System.out.print ( studentinfo [j] [k] + "\t"                         
                  );
            }

            System.out.println( );
       }

   }
公共类显示信息练习{
公共静态void main(字符串[]args){
int studentInfo[][]={{1,78,85},{2,83,90};
显示(学生信息);
}
公共静态无效显示(int数组[]){
对于(int j=0;j

请帮助。

您在
显示
方法声明中将其命名为
数组
。最简单的修改

public static void display( int array [ ] [ ] )

您还可以使用类似Java8+的lambdas重写整个程序

int[][] studentInfo = { { 1, 78, 85 }, { 2, 83, 90 } };
System.out.printf("%n%s%n",Stream.of(studentInfo) //
        .flatMapToInt(IntStream::of) //
        .mapToObj(String::valueOf) //
        .collect(Collectors.joining("\t")));

您使用的是在主函数上声明的局部变量studentInfo,位于显示函数内。您正在将此变量作为参数传递。您需要使用该参数的名称:

for ( int j = 0; j < array.length; j++ ) //

for ( int k = 0; k < array[j].length; k++)
System.out.print ( array[j] [k] + "\t" );
for(int j=0;j
//这是正确的版本

public class DisplayInfoExcercise {

    public static void main( String [ ] args )
    {
        int studentInfo [ ] [ ] = { {1, 78, 85}, {2, 83, 90} };

        display( studentInfo );
    }
    public static void display( int array [ ] [ ] )
    {
        for ( int j = 0; j < array.length; j++ ) //
        {
            System.out.println( );

            for ( int k = 0; k <array[j].length; k++)
                System.out.print ( array[j] [k] + "\t" );

        }
        System.out.println( );
    }

}
公共类显示信息练习{
公共静态void main(字符串[]args)
{
int studentInfo[][]={{1,78,85},{2,83,90};
显示(学生信息);
}
公共静态无效显示(int数组[])
{
对于(int j=0;jpublic class DisplayInfoExcercise {

    public static void main( String [ ] args )
    {
        int studentInfo [ ] [ ] = { {1, 78, 85}, {2, 83, 90} };

        display( studentInfo );
    }
    public static void display( int array [ ] [ ] )
    {
        for ( int j = 0; j < array.length; j++ ) //
        {
            System.out.println( );

            for ( int k = 0; k <array[j].length; k++)
                System.out.print ( array[j] [k] + "\t" );

        }
        System.out.println( );
    }

}