TheZopo

Lettres en commun entre 2 tableaux

Oct 27th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. public class ExosTableau {
  2.     public void main() {
  3.         tab1 = new char [10];
  4.         char[] tab1 = {'A','Z','G','J','U','K','E','B','V','D'};
  5.         tab2 = new char [10];
  6.         char[] tab2 = {'B','U','Z','K','X','V','N','L','M','E'};
  7.  
  8.         int i = 0; //Compteur de la boucle principale
  9.         int j = 0; //Compteur pour le placement des lettre en commun
  10.         int k = 0; //Compteur pour parcourir tab2
  11.  
  12.         for(i = 0; i < 10; i++) { //Choix de la lettre a comparé
  13.             for(k = j; k < 10; k++; { //Choix de la lettre comparé
  14.                 if(tab1[i] == tab2[k]) { //Si les deux lettres correspondent
  15.                     tab2[j] = tab[i]; //Mise du résultat dans tab2
  16.                     j++;
  17.                 }
  18.             }
  19.         }
  20.        
  21.         for(i = j; i < 10; i++) { //Suppression des lettres inutiles
  22.             tab2[i] = ' ';
  23.         }
  24.  
  25.         //Affichage du résultat
  26.         System.out.println("Lettres en commun : ");
  27.         for(i = 0; tab2[i] != ' '; i++) {
  28.             System.out.print(tab2[i] + ", ");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment