Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1.  
  2. public class Essai {
  3.  
  4. public static void main(String[] args) {
  5. int [][] tab = new int [13][13];
  6. int k=0;
  7. for (int i=2;i<13;i++) {
  8. for (int j=0;j<13;j++) {
  9. tab [i][j]=k;
  10. k++;
  11. }
  12. }
  13. affichageMat(tab);
  14. System.out.println("lignes débuts : " + lignes_début(tab));
  15. System.out.println("lignes fin : " + lignes_fin(tab));
  16. System.out.println("colonnes début : " + colonnes_début(tab));
  17. System.out.println("colonnes fin : " + colonnes_fin(tab));
  18. System.out.println("7 par 7 : " + taille_7x7(tab));
  19. }
  20.  
  21. public static void affichageMat(int[][] tab)
  22. {
  23. for (int i=0; i<tab.length;i++)
  24. {
  25. for (int j=0; j<tab[0].length;j++)
  26. System.out.print(tab[i][j]+" ");
  27. System.out.println();
  28. }
  29. System.out.println();
  30. }
  31.  
  32. public static boolean case_vide (int k) {
  33. boolean leBoolean = false;
  34. if (k==0) {
  35. leBoolean=true;
  36. }
  37. return leBoolean;
  38. }
  39.  
  40. //calcul le nombre de lignes du début vierges
  41. public static int lignes_début (int [][] tab) {
  42. int nombre_lignes_vierges_début=0;
  43. for (int i=0; i<tab.length; i++) {
  44. int k=0;
  45. for (int j=0; j<tab[0].length; j++) {
  46. if (case_vide(tab[i][j])==true) {
  47. k++;
  48. }
  49. }
  50. if (k==12) {
  51. nombre_lignes_vierges_début++;
  52. }
  53. else {
  54. break;
  55. }
  56. }
  57. return nombre_lignes_vierges_début;
  58. }
  59.  
  60. //calcul le nombre de lignes de la fin vierges
  61. public static int lignes_fin (int [][] tab) {
  62. int nombre_lignes_vierges_fin=0;
  63. for (int i=(tab.length - 1); i>=0; i--) {
  64. int k=0;
  65. for (int j=0; j<tab[0].length; j++) {
  66. if (case_vide(tab[i][j])==true) {
  67. k++;
  68. }
  69. }
  70. if (k==12) {
  71. nombre_lignes_vierges_fin++;
  72. }
  73. else {
  74. break;
  75. }
  76. }
  77. return nombre_lignes_vierges_fin;
  78. }
  79.  
  80. //calcul le nombre de colonnes du début vierges
  81. public static int colonnes_début (int [][] tab) {
  82. int nombre_colonnes_vierges_début=0;
  83. for (int i=0; i<tab.length; i++) {
  84. int k=0;
  85. for (int j=0; j<tab[0].length; j++) {
  86. if (case_vide(tab[j][i])==true) {
  87. k++;
  88. }
  89. }
  90. if (k==12) {
  91. nombre_colonnes_vierges_début++;
  92. }
  93. else {
  94. break;
  95. }
  96. }
  97. return nombre_colonnes_vierges_début;
  98. }
  99.  
  100. //calcul le nombre de colonnes de la fin vierges
  101. public static int colonnes_fin (int [][] tab) {
  102. int nombre_colonnes_vierges_début=0;
  103. for (int i=(tab.length - 1); i>=0; i--) {
  104. int k=0;
  105. for (int j=0; j<tab[0].length; j++) {
  106. if (case_vide(tab[j][i])==true) {
  107. k++;
  108. }
  109. }
  110. if (k==12) {
  111. nombre_colonnes_vierges_début++;
  112. }
  113. else {
  114. break;
  115. }
  116. }
  117. return nombre_colonnes_vierges_début;
  118. }
  119.  
  120. //Tableau de 7 par 7
  121. public static boolean taille_7x7(int[][] tab) {
  122. boolean leBoolean;
  123. leBoolean=true;
  124. //Plateau de 7 par 7.
  125. int nombre_lignes_vierges_début=0;
  126. int nombre_lignes_vierges_fin=0;
  127. int nombre_colonnes_vierges_début=0;
  128. int nombre_colonnes_vierges_fin=0;
  129.  
  130. nombre_lignes_vierges_début=lignes_début(tab);
  131. nombre_lignes_vierges_fin=lignes_fin(tab);
  132. nombre_colonnes_vierges_début=colonnes_début(tab);
  133. nombre_colonnes_vierges_fin=colonnes_fin(tab);
  134.  
  135. if ((nombre_lignes_vierges_début + nombre_lignes_vierges_fin) < 7) {
  136. leBoolean=false;
  137. }
  138. if ((nombre_colonnes_vierges_début + nombre_colonnes_vierges_fin) < 7) {
  139. leBoolean=false;
  140. }
  141.  
  142. return leBoolean;
  143. }
  144.  
  145.  
  146.  
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement