caio.augustoo 23 de mar. de 2016
Lf_Elesbao 23 de mar. de 2016
Opa!
Estou montando as matrizes nesse código:
public void montarMatriz ( int [] v ){
int tam = ( int ) sqrt ( v . length );
int m [][] = new int [ tam ][ tam ] ;
for ( int i = 0 ; i < v . length ; i ++ ){
m [ i / tam ][ i % tam ] = v [ i ] ;
}
if (( testarLinhas ( m , tam ) == true ) && ( testarColunas ( m , tam ) == true ) && ( testarDiagonalPrincipal ( m , tam ) == true ) && ( testarDiagonalSecundaria ( m , tam ) == true )){
imprimirMatriz ( m );
cont ++ ;
System . out . println ( teste ( m ));
if ( cont == 10 ){
JOptionPane . showMessageDialog ( null , teste ( m ));
}
}
}
Fiz dois códigos diferentes para imprimir a matriz, mas estou o usando o primeiro:
public String teste ( int [][] matrizes ) {
for ( int linha = 0 ; linha < matrizes . length ; linha ++ ) {
saidaMatriz += "|" ;
for ( int coluna = 0 ; coluna < matrizes . length ; coluna ++ ) {
saidaMatriz += Integer . toString ( matrizes [ linha ][ coluna ] ) + "" ;
}
saidaMatriz += "|\n" ;
}
// saidaMatriz += "\n" ;
return saidaMatriz ;
}
segundo:
public void imprimirMatriz ( int [][] mtz ){
for ( int linha = 0 ; linha < mtz . length ; linha ++ ) {
for ( int coluna = 0 ; coluna < mtz [ 0 ] . length ; coluna ++ ) {
System . out . print ( mtz [ linha ][ coluna ] + " " );
}
System . out . println ();
}
System . out . println ();
}
caio.augustoo 23 de mar. de 2016
O efeito desejado seria algo do tipo: Saída -> |n1| |n2| |n3| |n4| … ao invés de
|n1|
|n2|
|n3|
|n4|
?? Se for apenas isso, o seu \n é quem está quebrando linha.
Obs: se eu não soube interpretar a questão, me corrija, ok? Vlw
Lf_Elesbao 23 de mar. de 2016
O efeito desejado seria
Matriz 1 Matriz 2
[LINHA 1] [LINHA 1]
[LINHA 2] [LINHA 2]
[LINHA 3] [LINHA 3]
E assim por diante