Syntax error, insert "Dimensions" to complete ReferenceType

1
import java.util.Scanner;

public class ModosNormales {
    public static void main(String[] ar) {
        Scanner teclado=new Scanner(System.in);
        int nx,ny,c,n;
        float lx;
        float ly;

        float fn;
        c=172;

        System.out.print("Ingrese valor de nx:");
        nx=teclado.nextInt();
        System.out.print("Ingrese valor de ny:");
        ny=teclado.nextInt();
        System.out.print("Ingrese lx:");
        lx=teclado.nextFloat();
        System.out.print("Ingrese ly:");
        ly=teclado.nextFloat();
        fn=c*(float) Math.sqrt(Math.pow((nx/lx),2)+(float)(Math.pow((ny/ly),2)));

        System.out.print("Fn=");
        System.out.println(fn);

        for(n=0;n<10;n++) { 

            int nx1,ny1;
            float fn1;
            ArrayList<float> fn1= new ArrayList();


               System.out.print("Ingrese valor de nx:");
               nx1=teclado.nextInt();
               System.out.print("Ingrese valor de ny:");
               ny1=teclado.nextInt();
               fn1.add(n,c*(float) Math.sqrt(Math.pow((nx/lx),2)+(float)(Math.pow((ny/ly),2)))); //en cada posición del array guardas un valor de fn1
               System.out.print("Fn=");
               System.out.println(fn1.get(n));


            }


            for (int i=0;i<fn1.size()-1;i++)
             {
                  if (fn1.get(i) = fn1.get(i+1))
             {
                aux++; //si el elemento actual es igual al siguiente, incrementamos la variable aux
              }
            }

               if(fn1[n]>=500)
        {System.out.println("Frecuencia mayor o igual a 500Hz"); break;





    }}}

ArrayList<float> fn1= new ArrayList();

why is he telling me here? :

  

Syntax error, insert "Dimensions" to complete ReferenceType?

    
asked by Matias Retamales 10.10.2017 в 01:08
source

1 answer

0

Your code is riddled with errors.

For example:

  • The main method:

    public static void main(String[] ar) {
    
  • You declare fn1 as float and at the same time as ArrayList . Also, you do it in a loop.

     for(n=0;n<10;n++) { 
        int nx1,ny1;
        float fn1;
        ArrayList<float> fn1= new ArrayList();
    
  • This comparison lacks an equality sign:

    if (fn1.get(i) = fn1.get(i+1))
    
  • The variable aux++; is not declared.

  • Here if(fn1[n]>=500) should use get .

  • As a comment, I can not see the usefulness of the last loop for and the last if of the code.

    I have corrected those points and perhaps others, declaring the variables in their time, etc. The code works (does not give errors).

    Code:

    import java.util.Scanner;
    
    public class ModosNormales {
        public static void main(String args[]) {
    
            Scanner teclado = new Scanner(System.in);
            ArrayList<Float> fn1 = new ArrayList();
            int aux = 0; //No sé si debe valer 0, si no le pones el valor inicial que deba llevar
            int nx, ny, c, n;
            float lx;
            float ly;
            float fn;
            c = 172;
    
            System.out.print("Ingrese valor de nx:");
            nx = teclado.nextInt();
            System.out.print("Ingrese valor de ny:");
            ny = teclado.nextInt();
            System.out.print("Ingrese lx:");
            lx = teclado.nextFloat();
            System.out.print("Ingrese ly:");
            ly = teclado.nextFloat();
            fn = c * (float) Math.sqrt(Math.pow((nx / lx), 2) + (float) (Math.pow((ny / ly), 2)));
    
            System.out.print("Fn=");
            System.out.println(fn);
    
            for (n = 0; n < 10; n++) {
    
                int nx1, ny1;
    //            float fn1;
    
                System.out.print("Ingrese valor de nx:");
                nx1 = teclado.nextInt();
                System.out.print("Ingrese valor de ny:");
                ny1 = teclado.nextInt();
                fn1.add(n, c * (float) Math.sqrt(Math.pow((nx / lx), 2) + (float) (Math.pow((ny / ly), 2)))); //en cada posición del array guardas un valor de fn1
                System.out.print("Fn=");
                System.out.println(fn1.get(n));
    
            }
    
            for (int i = 0; i < fn1.size() - 1; i++) {
                if (fn1.get(i) == fn1.get(i + 1)) {
                    aux++; //si el elemento actual es igual al siguiente, incrementamos la variable aux
                }
            }
    
            if (fn1.get(n) >= 500) {
                System.out.println("Frecuencia mayor o igual a 500Hz");
            }
    
        }
    }
    

    A test

    Ingrese valor de nx:10
    Ingrese valor de ny:20
    Ingrese lx:5
    Ingrese ly:7
    Fn=599.865
    
        
    answered by 10.10.2017 в 12:15