Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Essai {
- public static void main(String[] args) {
- int [][] tab = new int [13][13];
- int k=0;
- for (int i=5;i<10;i++) {
- for (int j=2;j<7;j++) {
- tab [i][j]=k;
- k++;
- }
- }
- affichageMat(tab);
- System.out.println("lignes débuts : " + lignes_début(tab));
- System.out.println("lignes fin : " + lignes_fin(tab));
- System.out.println("colonnes début : " + colonnes_début(tab));
- System.out.println("colonnes fin : " + colonnes_fin(tab));
- System.out.println("7 par 7 : " + taille_7x7(tab));
- }
- public static void affichageMat(int[][] tab)
- {
- for (int i=0; i<tab.length;i++)
- {
- for (int j=0; j<tab[0].length;j++)
- System.out.print(tab[i][j]+" ");
- System.out.println();
- }
- System.out.println();
- }
- public static boolean case_vide (int k) {
- return k==0;
- }
- //calcul le nombre de lignes du début vierges
- public static int lignes_début (int [][] tab) {
- int nombre_lignes_vierges_début=0;
- for (int i=0; i<tab.length; i++) {
- int k=0;
- for (int j=0; j<tab[i].length; j++) {
- if (case_vide(tab[i][j])==true) {
- k++;
- }
- }
- if (k==tab[i].length) {
- nombre_lignes_vierges_début++;
- }
- else {
- break;
- }
- }
- return nombre_lignes_vierges_début;
- }
- //calcul le nombre de lignes de la fin vierges
- public static int lignes_fin (int [][] tab) {
- int nombre_lignes_vierges_fin=0;
- for (int i=(tab.length - 1); i>=0; i--) {
- int k=0;
- for (int j=0; j<tab[i].length; j++) {
- if (case_vide(tab[i][j])==true) {
- k++;
- }
- }
- if (k==tab[i].length) {
- nombre_lignes_vierges_fin++;
- }
- else {
- break;
- }
- }
- return nombre_lignes_vierges_fin;
- }
- //calcul le nombre de colonnes du début vierges
- public static int colonnes_début (int [][] tab) {
- int nombre_colonnes_vierges_début=0;
- for (int i=0; i<tab.length; i++) {
- int k=0;
- for (int j=0; j<tab[i].length; j++) {
- if (case_vide(tab[j][i])==true) {
- k++;
- }
- }
- if (k==tab[i].length) {
- nombre_colonnes_vierges_début++;
- }
- else {
- break;
- }
- }
- return nombre_colonnes_vierges_début;
- }
- //calcul le nombre de colonnes de la fin vierges
- public static int colonnes_fin (int [][] tab) {
- int nombre_colonnes_vierges_début=0;
- for (int i=(tab.length - 1); i>=0; i--) {
- int k=0;
- for (int j=0; j<tab[i].length; j++) {
- if (case_vide(tab[j][i])==true) {
- k++;
- }
- }
- if (k==tab[i].length) {
- nombre_colonnes_vierges_début++;
- }
- else {
- break;
- }
- }
- return nombre_colonnes_vierges_début;
- }
- //Tableau de 7 par 7
- public static boolean taille_7x7(int[][] tab) {
- boolean leBoolean;
- leBoolean=true;
- //Plateau de 7 par 7.
- int nombre_lignes_vierges_début=0;
- int nombre_lignes_vierges_fin=0;
- int nombre_colonnes_vierges_début=0;
- int nombre_colonnes_vierges_fin=0;
- nombre_lignes_vierges_début=lignes_début(tab);
- nombre_lignes_vierges_fin=lignes_fin(tab);
- nombre_colonnes_vierges_début=colonnes_début(tab);
- nombre_colonnes_vierges_fin=colonnes_fin(tab);
- if ((nombre_lignes_vierges_début + nombre_lignes_vierges_fin) < 7) {
- leBoolean=false;
- }
- if ((nombre_colonnes_vierges_début + nombre_colonnes_vierges_fin) < 7) {
- leBoolean=false;
- }
- return leBoolean;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement