Advertisement
Guest User

Untitled

a guest
May 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1.  
  2. public class testTabNonTriee {
  3.  
  4. //private static int [] tabEntiers;
  5. private static final int TAILLE = 10;
  6. //private int nombreDEntiers;
  7.  
  8. static int[] tabEntiers = {3,4,5};
  9.  
  10.  
  11.  
  12. public static void main(String[] args) {
  13.  
  14. // tabEntiers = new int[TAILLE];
  15. // nombreDEntiers = 0;
  16. //
  17. //
  18. // tabEntiers[0] = 1;
  19. // tabEntiers[1] = 3;
  20. // tabEntiers[2] = 3;
  21. // tabEntiers[3] = 4;
  22. // tabEntiers[4] = 3;
  23.  
  24. //nombreDEntiers = 3;
  25.  
  26. supprimerOccurences(5);
  27.  
  28. for (int i=0 ; i<tabEntiers.length ; i++) {
  29. System.out.println(tabEntiers[i]);
  30. }
  31. }
  32.  
  33. private static void supprimerOccurences(int unEntier) {
  34. int suppression = 0;
  35. int nombreDEntiers = 3;
  36. int i=0;
  37.  
  38. while(i<nombreDEntiers) {
  39. if(tabEntiers[i]==unEntier) {
  40. nombreDEntiers--;
  41. tabEntiers[i] = tabEntiers[nombreDEntiers];
  42. for (int j=i ; j<nombreDEntiers ; j++)
  43. if(tabEntiers[nombreDEntiers] == tabEntiers[j]) {
  44. tabEntiers[nombreDEntiers] = 0;
  45. }
  46. }
  47. else {
  48. i++;
  49. }
  50. }
  51.  
  52.  
  53.  
  54. // while(i<nombreDEntiers){
  55. // if(tabEntiers[i]==unEntier){ //i = [0] (2)
  56. //
  57. // for (int j = i ; j<nombreDEntiers-1 ; j++) { // T1 :j=0, donc i=0 au 1er tour ; j=0 < 4 ; j+1 , T2 : j=1, i=1 & <2
  58. // tabEntiers[j] = tabEntiers[j+1]; // tabEntiers index 0 = tabEntiers index 1
  59. // // tabEntiers[nombreDEntiers-1] = 0; //tabEntiers[3] aura la valeur 0
  60. // //tabEntier2
  61. // nombreDEntiers--;
  62. //
  63. //
  64. // }
  65. //
  66. // }
  67. // else{
  68. // i++; //T1 : i=1
  69. // for(int j=i ; j<nombreDEntiers ;j++) {
  70. // if(tabEntiers[j-1] == tabEntiers[j]) {
  71. // tabEntiers[j+1] = 0;
  72. // }
  73. // }
  74. // if(tabEntiers[i-1] == tabEntiers[i] ) {
  75. // tabEntiers[i] = tabEntiers[i+1];
  76. // tabEntiers[i+1] = 0;
  77. // }
  78. //
  79. // suppression++;
  80. //
  81. // }
  82. //
  83. // }
  84.  
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement