本文介绍了在java中找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 DFM.java



这个部分在主类中

  Algebra.vect dx = new Algebra.vect(new double [] {2.0,3.0,4.0}); 
Algebra.matrix eij = new Algebra.matrix();
System.out.println(eij.get(1,1));
dx.set(1,4.0);
System.out.println(dx.get(1));

这是 Algebra.java

  class代数{
public static class vect
{
double [] v = new double [3];
public vect()
{
v [0] = v [1] = v [2] = 0;
}
public vect(double [] v)
{
this.v = v;
}
int tamanho()
{
return v.length;
}
double get(int i)
{
return v [i];

void set(double [] v)
{
this.v = v;
}
void set(int i,double n)
{
v [i] = n;

void print()
{
for(int i = 0; i< v.length; i = i + 1)
System.out。 print(v [i] +);
System.out.print(\\\
);



public static class operacoes
{
double prodInt(vect v1,vect v2)
{
return v1.get(0)* v2.get(0)+ v1.get(1)* v2.get(1)+ v1.get(2)* v2.get(2);

double [] somaVV(vect v1,vect v2)
{
return new double [] {v1.get(0)+ v2.get(0),v1 .get(1)+ v2.get(1),v1.get(2)+ v2.get(2)};

double [] prodMV(matrix m,vect v)
{
double [] Soma = new double [3];
Soma [0] = Soma [1] = Soma [2] = 0; (int i = 0; i {
for(int j = 0; i {
Soma [i] = m [i] [j] * v [j]
}
}
返回Soma;



$ b public static class matrix
{
double [] [] m = new double [3] [3] ; (int i = 0; i {
for(int j = 0; i {
m [i] [j] = 0;


$ b public matrix(double [] [] m)
{
this.m = m;
}
double get(int i,int j)
{
return m [i] [j];

void set(double [] [] m)
{
this.m = m;

void set(int i,int j,double n)
{
m [i] [j] = n;

void print()
{
for(int i = 0; i< v.tamanho(); i = i + 1)
{
for(int j = 0; i< v.tamanho(); j = j + 1)
{
System.out.print(m [i] [j] +);
}
System.out.print(\\\
);
}
System.out.print(\\\
);


code $ p
$ b

错误

  DFM.java:29:error:can not find symbol 
System.out.println(eij.get(1,1) );
$
符号:方法get(int,int)
位置:矩阵类型的变量eij
1错误

但是当我用eij方法的调用在注释中运行的时候

  dx .SET(1,4.0); 
System.out.println(dx.get(1));

这个dx是vect类的部分,
运行良好,代码是类似于矩阵类



任何人都可以帮忙吗?

解决方案

看起来像矩阵的签名 - 类的 get - 方法缺少修饰符 public :

  double get(int i,int j)

所以它具有默认(包)可见性。将它改为

  public double get(int i,int j)
pre>

,它应该可以工作。


This is in DFM.java

This part is in the main class

Algebra.vect dx = new Algebra.vect(new double[] {2.0,3.0,4.0});
Algebra.matrix eij = new Algebra.matrix();
System.out.println(eij.get(1,1));
dx.set(1,4.0);
System.out.println(dx.get(1));

This is in Algebra.java

class Algebra {
public static class vect
{
    double[] v = new double[3];
    public vect()
    {
        v[0]=v[1]=v[2]=0;
    }
    public vect(double[] v)
    {
        this.v=v;
    }
    int tamanho()
    {
        return v.length;
    }
    double get(int i)
    {
        return v[i];
    }
    void set(double[] v)
    {
        this.v=v;
    }
    void set(int i, double n)
    {
        v[i]=n;
    }
    void print()
    {
        for(int i=0; i < v.length; i = i + 1)
            System.out.print(v[i] + " ");
        System.out.print("\n");
    }
}

public static class operacoes
{
    double prodInt(vect v1, vect v2)
    {
        return v1.get(0)*v2.get(0)+v1.get(1)*v2.get(1)+v1.get(2)*v2.get(2);
    }
    double[] somaVV(vect v1, vect v2)
    {
        return new double[] {v1.get(0)+v2.get(0), v1.get(1)+v2.get(1), v1.get(2)+v2.get(2) };
    }
    double[] prodMV(matrix m, vect v)
    {
        double[] Soma = new double[3];
        Soma[0]=Soma[1]=Soma[2]=0;
        for(int i=0;i< v.tamanho();i=i+1)
        {
            for(int j=0;i< v.tamanho();j=j+1)
            {
                Soma[i]=m[i][j]*v[j];
            }
        }
        return Soma;
    }

}

public static class matrix
{
    double[][] m = new double[3][3];
    public matrix()
    {
        for(int i=0;i< v.tamanho();i=i+1)
        {
            for(int j=0;i< v.tamanho();j=j+1)
            {
                m[i][j]=0;
            }
        }
    }
    public matrix(double[][] m )
    {
        this.m=m;
    }
    double get(int i,int j)
    {
        return m[i][j];
    }
    void set(double [][] m)
    {
        this.m=m;
    }
    void set(int i,int j, double n)
    {
        m[i][j]=n;
    }
    void print()
    {
        for(int i=0;i< v.tamanho();i=i+1)
        {
            for(int j=0;i< v.tamanho();j=j+1)
            {
                System.out.print(m[i][j] + " ");
            }
            System.out.print("\n");
        }
        System.out.print("\n");
    }
}

Error

DFM.java:29: error: cannot find symbol
System.out.println(eij.get(1,1));
                      ^
symbol:   method get(int,int)
location: variable eij of type matrix
1 error

But when I ran with calls of eij method in commentary

dx.set(1,4.0);
System.out.println(dx.get(1));

This part where dx is of the vect class,worked well and is the code is similar to the matrix class

Can anyone help please?

解决方案

Looks like the signature of your matrix-class's get-method is missing the modifier public:

 double get(int i,int j)

so it has "default" (package) visibility. Change it to

 public double get(int i,int j)

and it should work.

这篇关于在java中找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:00