A voir également:
- Java tableau dynamique
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Tableau croisé dynamique - Guide
- Tableau word - Guide
- Exemple tableau croisé dynamique télécharger - Télécharger - Tableur
1 réponse
Voilà un exemple fonctionnel :
import java.util.Scanner;
public class LauncherTwoDimArrayInput {
private int[][] data;
private int rowMax;
private int colMax;
public LauncherTwoDimArrayInput(int row, int col) {
this.rowMax = row;
this.colMax = col;
this.data = new int[this.rowMax][this.colMax];
}
public void fill() {
Scanner in = new Scanner(System.in);
for (int row = 0; row < this.data.length; row++) {
for (int col = 0; col < this.data[row].length; col++) {
System.out.println("Entrer un entier :");
this.data[row][col] = in.nextInt();
}
System.out.println();
}
}
@Override
public String toString() {
String ret = "";
for (int row = 0; row < this.data.length; row++) {
for (int col = 0; col < this.data[row].length; col++) {
ret += data[row][col];
}
ret += '\n';
}
return ret;
}
public static void main(String[] args) {
LauncherTwoDimArrayInput launcherTwoDimArrayInput = new LauncherTwoDimArrayInput(2, 3);
launcherTwoDimArrayInput.fill();
System.out.println(launcherTwoDimArrayInput.toString());
}
}