如果您看到我在下面的矩陣中保留的數字是根據我的清單,還有所有這些數字,並且當我嘗試打印清單時,只需發送給我很多這些清單: 我@ 7852e922這是內存地址?並且如果打印的對象。感謝您的關注。無法打印我的清單
package estructurasDeDatos;
import java.util.List;
import java.util.LinkedList;
public class Matriz {
private static Scanner read;
public static void main(String[] args){
/*read = new Scanner(System.in);
System.out.println("Ingrese el numero de filas y columnas: ");
int f = read.nextInt();
int c = read.nextInt();*/
LinkedList ll = new LinkedList();
System.out.println(" ** ** *** ******* **** ***** *** ***** ***** ");
System.out.println(" * ** * * * * * * * * * * ");
System.out.println(" * ** * * * * * * * * * * ");
System.out.println(" * * ******* * **** * * *** **** ");
System.out.println(" * * * * * * * * * * * ");
System.out.println(" * * * * * * * * * * * ");
System.out.println(" * * * * * * * ***** *** ***** ***** ");
System.out.println("###########################################################################");
int mt [][] = new int[10][10];//Genero la matriz con dos arreglos con una cantidad que yo quiera de
//filas y columnas.
int num;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{//Genero un numero aleatorio entre 0 y 100
num=(int)(Math.random()*100);
//Asigno el numero generado a la matriz
mt[i][j]=num;
ll.push(mt);
}
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{//Imprimo la celdad de la matriz
System.out.print(mt[i][j]+"\t");
}
System.out.println();
}
System.out.println("###########################################################################");
System.out.println("\n\n");
System.out.println("LOS NUMEROS DE LA DIAGONAL PRINCIPAL:");
System.out.print(mt[0][0]+" "+mt[1][1]+" "+mt[2][2]+" "+mt[3][3]+" "+mt[4][4]+" "+mt[5][5]+" "+mt[6][6]+" "+mt[7][7]+" "+mt[8][8]+" "+mt[9][9]+"\n\n");
int sumatoriadiap=mt[0][0]+mt[1][1]+mt[2][2]+mt[3][3]+mt[4][4]+mt[5][5]+mt[6][6]+mt[7][7]+mt[8][8]+mt[9][9];
System.out.println("La sumatoria de la diagonal principal es: \n"+sumatoriadiap);
System.out.println("El promedio de la diagonal principal es : \n"+sumatoriadiap/10);
////////////////////////////////////////////////////////////////////////////////////////////////////////
System.out.println("LOS NUMEROS DE LA DIAGONAL SECUNDARIA:");
System.out.print(mt[0][9]+" "+mt[1][8]+" "+mt[2][7]+" "+mt[3][6]+" "+mt[4][5]+" "+mt[5][4]+" "+mt[6][3]+" "+mt[7][2]+" "+mt[8][1]+" "+mt[9][0]+"\n\n");
int sumatoriadias=mt[0][9]+mt[1][8]+mt[2][7]+mt[3][6]+mt[4][5]+mt[5][4]+mt[6][3]+mt[7][2]+mt[8][1]+mt[9][0];
System.out.println("La sumatoria de la diagonal principal es: \n"+sumatoriadias);
System.out.println("El promedio de la diagonal principal es : \n"+sumatoriadias/10);
}
}
對於初學者來說,我沒有看到你在哪裏」重新列印清單。另外,你正在處理沒有'toString()'重寫的數組 - 你看到的是數組的哈希碼。第三,你的鏈表沒有類型,這使得它工作......有趣...... – Makoto 2014-09-20 06:54:04