Silver
Silver

Reputation: 35

Problems with compilation

This is the compiler error that I'm getting:

JogarLightmare.java:105: error: expected

    public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){
                                                                  ^

JogarLightmare.java:105: error: not a statement

    public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){
                                                                       ^

JogarLightmare.java:105: error: ';' expected

    public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){
                                                                             ^

JogarLightmare.java:105: error: expected

    public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){
                                                                                           ^

JogarLightmare.java:105: error: not a statement

    public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){
                                                                                                ^

JogarLightmare.java:105: error: ';' expected

    public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){



This is the method in question. I've already verified { } but I don't know where is the problem:

public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){

      char z = '_';
      char m = 'M';
      char o = 'O';
      char a = '@';

      if(fim == 2){
        o = '*';
      }

      StringBuilder caminho = new StringBuilder(int colunas);

      for(int j = 1; j <= linhas; j = j + 1){
        for(int i = 1; i <= colunas; i = i + 1){

          if(i != posMonius && i != posOutro){
            caminho.append(z);
          }else{

            if(i == posMonius && i == posOutro){
              caminho.append(a);
            }else{

               if(i == posMonius){
                 caminho.append(m);
               }else{
                  caminho.append(o);

                }
             }
           }

        }

        if(j % 2 == 0){
          System.out.println(caminho.reverse().toString());
        }else{
          System.out.println(caminho.toString());
         }

      }

    }

Upvotes: 0

Views: 51

Answers (1)

Danylo Zatorsky
Danylo Zatorsky

Reputation: 6104

Replace this line:

StringBuilder caminho = new StringBuilder(int colunas);

with this line:

StringBuilder caminho = new StringBuilder(colunas);

The thing is that the syntax new StringBuilder(int colunas); is not valid. int colunas is usually used to declare a variable of type int, but here you accept this variable as a parameter which doesn't need to specify type again. The variable itself was already declared in this line:

public static void imprimeCaminho(int posMonius, int posOutro, int linhas, int colunas, int fim){

Upvotes: 1

Related Questions