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
|
package javaapplication2;
import java.util.Scanner;
public class JavaApplication2 {
public static void main(String[] args) {
int [][] tableau=new int [2][3];
int [][] tableau2=new int [3][2];
System.out.println("entrer les valeur du tableau de 2 lignes et 3 colones ");
remplir (tableau);
System.out.println("voila votre tableau de deux dimension");
afficher (tableau);
System.out.println("voila votre tableau inverse: ");
inverser(tableau,tableau2);
afficher(tableau2);
}
static void remplir(int [][] tableau){
Scanner sc=new Scanner(System.in);
for (int i=0;i<tableau.length;i++){
for (int j=0;j<tableau[i].length;j++){
tableau[i][j]=sc.nextInt();
}
}
}
static void afficher(int [][] tableau ){
for (int i=0;i<tableau.length;i++){
for (int j=0;j<tableau[i].length;j++){
System.out.print(tableau [i][j]+" ");
}
System.out.println();
}
}
static void inverser(int [][] tableau,int [][] tableau2){
for(int i=0;i<3;i++){
for(int j=0;j<2;j++){
tableau2[i][j]=tableau[j][i];
}
}
}
}
voila un exemple:
entrer les valeur du tableau de 2 lignes et 3 colones
1
2
3
4
5
6
voila votre tableau de deux dimension
1 2 3
4 5 6
voila votre tableau inverse:
1 4
2 5
3 6 |