TOPIC

Presentetion Error 0%

GiovanniSchenato asked 3 years ago

Como isso é possivel?

import java.io.IOException;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);

        boolean continuar = true;

        while(continuar){

            int tamanho = scan.nextInt();

            if(tamanho == 0) continuar = false;

            int M[][] = new int[tamanho][tamanho];

            int iniMatriz = 0;
            int fimMatriz = tamanho;
            int elemento = 1;

            while(true)
            {
                for (int linha = iniMatriz; linha < fimMatriz; linha++)
                    for (int coluna = iniMatriz; coluna < fimMatriz; coluna++)
                        M[linha][coluna] = elemento;

                if (fimMatriz == 0)break;

                fimMatriz--;
                iniMatriz++;
                elemento++;

            }

            for(int i = 0; i<tamanho; i++){
                for(int j = 0; j<tamanho; j++){
                    if (j == 0) {
                        System.out.printf("%3d" , M[i][j]);
                    } else {
                        System.out.printf("%4d", M[i][j]);
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
        //System.out.println();
    }

}

Remember not post solutions. Your post may be reviewed by our moderators.

  • v_guilherme replied 2 years ago

    Tive o mesmo erro em Javascript, e o problema era até simples. Tenham cuidado com a saída final... em alguns casos de teste são inseridos dois "\n" ao fim do arquivo.

  • Fabreu22_ replied 2 years ago

    estou com esse mesmo erro '-'