1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
   | package MagicMatrix;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
 
import com.lowagie.text.pdf.codec.Base64.OutputStream;
 
import ucar.nc2.NCdump;
import ucar.nc2.NetcdfFile;
 
 
public class MatriceMGM {
	private long[][] coeff = null;
 
	/**
         * Constructeur Matrice
         * 
         * @param int i - ligne int j - colonne
         */
	public MatriceMGM(int i, int j) {
		this.setLength(i, j);
	}
 
	public MatriceMGM() {
		this(0, 0);
	}
 
	public MatriceMGM(long[][] mat) {
		this.coeff = mat;
	}
 
	// définit une matrice de type long[][]
	public void setMatrice(long[][] mat) {
		this.coeff = mat;
	}
 
	// définit une valeur à la position i et j
	// i - ligne
	// j - col
	public void setValue(int i, int j, long value) {
 
		this.coeff[i][j] = value;
	}
/**la question est: comment faire pour que
        le resultat de coeff[i][j] le soit pas un scalaire mais un tableau de 3 elts cad
        coeff[i][j]=(0,1,0) par exemple
        **/
 
 
 
//	public void setValue(int i, int j, long[] value) {
//		value=new long[3]
//		
//		this.coeff[i][j] = value[i];
//	}
 
 
	// on définit la taille de la matrice
	public void setLength(int i, int j) {
		this.coeff = new long[i][j];
	}
 
	// retourne la matrice sous forme du type long[][]
	public long[][] getMatrice() {
		return this.coeff;
	}
 
	// retourne le nombre de ligne
	public int getRows() {
		return this.coeff.length;
	}
 
	// retourne le nombre de colonne
	public int getColumns() {
		return this.coeff[0].length;
	}
 
	// retourne la valeur à la position i et j
	public long getValue(int i, int j) {
		return this.coeff[i][j];
	}
 
	public String toString() {
		String out = "\n[\n";
 
		for (int i = 0; i < this.getRows(); i++) {
			for (int j = 0; j < this.getColumns(); j++)
				out += this.coeff[i][j] + "\t";
 
			out += "\n";
		}
 
		return out + "]";
	}
 
	public static void main(String[] args) {
		// matrice mgm
		MatriceMGM a = new MatriceMGM();
		a.setMatrice(new long[][] { { 0, 1, 1, 0, 0 }, // 1
				{ 1, 0, 1, 1, 1, }, // 2
				{ 1, 1, 0, 0, 1, }, // 3
				{ 0, 1, 0, 0, 0, }, // 4
				{ 0, 1, 0, 0, 1, },// 5
		});
		System.out.println("matrice a :\n " + a);
		MatriceMGM x = new MatriceMGM(new long[][] { { 0, 1, 0, 0 },
				{ 1, 0, 0, 0 }, { 0, 0, 1, 1 }, { 0, 0, 0, 1 } });
 
		MatriceMGM mgm = new MatriceMGM();
		// taille mat
		mgm.setLength(10, 10);
		//System.out.println("taille mat " + mgm);
		// remplissage de la matrice
		// for (int i = 0; i < 10; i++) {
		// for (int j = 0; j < 10; j++) {
		// int ligne = i;
		// System.out.println("val " + ligne);
		//
		// int col = j;
		//
		// long[] v = { 0, 0, 1 };
		// mgm.setValue(ligne, col, v);
		// }
		// }
		//
		// System.out.println("mgm \n " + mgm.toString());
 
	}
 
} | 
Partager