JAVA-can';不要调用我的数组方法

JAVA-can';不要调用我的数组方法,java,arrays,methods,call,Java,Arrays,Methods,Call,Eclipse说:“chiffres不能解析为变量”,如何修复调用方法 public class Table { public static void main(String[] args) { Tableau1 table = new Tableau1(); table.CreerTable(); table.AfficherTable(chiffres); }} 第部分: 并使用数组类Tableau1:来声明它 public class Tableau1

Eclipse说:“chiffres不能解析为变量”,如何修复调用方法

public class Table {

public static void main(String[] args) {


    Tableau1 table = new Tableau1();


    table.CreerTable();
    table.AfficherTable(chiffres);

}}
第部分: 并使用数组类Tableau1:来声明它

public class Tableau1 {
int [][] chiffres;
int nombre;
public void CreerTable(){

    int[][] chiffres= {{11,01,3},
                        {12,02,4},
                        {12,03,5}};
    //edited
    this.chiffres=chiffres;


}

public int[][] AfficherTable(int[][] chiffres){
    this.nombre=12;
    for(int i=0;i<2;i++){

    System.out.println("essai"+chiffres[i][1]);
    if(chiffres[i][0]==nombre){System.out.println("ma ligne ="+chiffres[i][0]+","+chiffres[i][1]+","+chiffres[i][2]);
                                };

                        }
                        return chiffres;
}
公共类表1{
int[][]chiffres;
国际名词;
公共文件目录{
int[]chiffres={{11,01,3},
{12,02,4},
{12,03,5}};
//编辑
这个。chiffres=chiffres;
}
公共int[][]可粘贴(int[][]chiffres){
这个。nombre=12;

对于(inti=0;i,这里有3个问题

问题1:

1) 方法
AfficherTable(chiffres)
不需要传递参数,因为它是实例成员

你只要打个电话就可以了

table.AfficherTable();
这就解决了你的问题

在做第二道题之前

问题2:

2) 您可以将chiffres
作为实例成员
int[]chiffres;

您正在初始化它,它位于构造函数中

public void CreerTable(){

    int[][] chiffres= {{11,01,3},
                        {12,02,4},
                        {12,03,5}};

}
但是如果你仔细观察,你又在创建新的数组了。这是行不通的,因为你正在创建新的数组,却忘记了你的实例成员

将构造函数更改为

public void CreerTable(){

        chiffres= new  int[3][3] {{11,01,3},
                            {12,02,4},
                            {12,03,5}};

    }
问题3:

更改该构造函数后,由于您在同一个类成员中使用它,因此不需要接收它

public int[][] AfficherTable(){

我想你现在会好起来的。

你这里有三个问题

    table.CreerTable();
    table.AfficherTable(chiffres);
问题1:

1) 方法
AfficherTable(chiffres)
不需要传递参数,因为它是实例成员

你只要打个电话就可以了

table.AfficherTable();
这就解决了你的问题

在做第二道题之前

问题2:

2) 您可以将chiffres作为实例成员
int[]chiffres;

您正在初始化它,它位于构造函数中

public void CreerTable(){

    int[][] chiffres= {{11,01,3},
                        {12,02,4},
                        {12,03,5}};

}
但是如果你仔细观察,你又在创建新的数组了。这是行不通的,因为你正在创建新的数组,却忘记了你的实例成员

将构造函数更改为

public void CreerTable(){

        chiffres= new  int[3][3] {{11,01,3},
                            {12,02,4},
                            {12,03,5}};

    }
问题3:

更改该构造函数后,由于您在同一个类成员中使用它,因此不需要接收它

public int[][] AfficherTable(){
我想你现在会好起来的

    table.CreerTable();
    table.AfficherTable(chiffres);
通过解析chiffres,它在类表中搜索,因为您没有指定chiffres来自Tableau1。 因此,解决办法是:

    table.CreerTable();
    table.AfficherTable(table.chiffres);
通过解析chiffres,它在类表中搜索,因为您没有指定chiffres来自Tableau1。 因此,解决办法是:

    table.CreerTable();
    table.AfficherTable(table.chiffres);

chiffers既不是主方法的局部变量,也不是类表的字段,这就是错误的原因。

chiffers既不是主方法的局部变量,也不是类表的字段,这就是错误的原因。

是的,它是什么,声明在哪里?对不起,我粘贴了twiceDid,你伪造了吗t声明变量“chiffres”?我在你的主方法的任何地方都看不到它。@chris_cx变量在使用前需要声明。你在代码中声明了它在哪里?这是你的完整代码吗?我没有看到chiffres的任何声明?!它是Tableau1中的类型吗?还是一个类?!是的,它是什么以及声明在哪里?对不起,我粘贴了twiceDid你忘记声明变量了吗能干的“chiffres”?我在你的主方法的任何地方都看不到它。@chris_cx变量在使用之前需要声明。你在代码中声明它的位置?这是你的完整代码吗?我没有看到chiffres的声明吗?它是Tableau1中的类型吗?还是它是一个类?谢谢,有更简单的解决方案,但我会测试你的,对于未来的库,有更简单的解决方案离子,但我会测试你的,为将来的
this.chiffres=chiffres;
this.chiffres=chiffres;