-1

Why is my code returning this error? I've made any mistake? I can not see my error in this code. Can anybody help me?

The code is bellow:

    public static void minMax(int m[][])
    {
        int menor = 0;
        int maior = 0;
        int i = 0;
        int j = 0;
        int posicao = 0;

        for(i = 0; i < 4;i++)
        {
            for(j = 0; j < 5; j++)
            {
                if((i == 0) && (j == 0))
                {
                    menor = m[i][j];
                    posicao = i;
                }

                else
                {
                    if(m[i][j] < menor)
                    {
                        menor = m[i][j];
                        posicao = i;
                    }
                }
            }
        }

        for (i = posicao;;)
        {
            for(j = 0; j < 5; j++)
            {
                if(j == 0)
                {
                    maior = m[i][j];
                }

                else
                {
                    if(m[i][j] > maior)
                    {
                        maior = m[i][j];
                    }
                }
            }

        }

        System.out.println("\n\nThe smallest element of the array: " + menor);
        System.out.println("The line of the smallest element: " + posicao);
        System.out.printf("MINMAX element %d encountered at the position: [%d][%d]", maior, i, j);
    }

The error is pointed by Eclipse in this line:

System.out.println("\n\nThe smallest element of the array: " + menor);

LGirdwood
  • 1
  • 1

1 Answers1

2

Looks like your for loop defined as for (i = posicao;;) above your prints never finishes, there is no exit case

Andreas
  • 154,647
  • 11
  • 152
  • 247
RareTyler
  • 131
  • 1
  • 2
  • 11