Advertisement
Tecnelm

Untitled

Nov 11th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Code_analyse_frequence
  4. {
  5.     static ArrayList antidoublon ( ArrayList<Character> newlist)
  6.     {
  7.         ArrayList <Character> List = new ArrayList<Character>();
  8.         for(int i = 0 ; i < newlist.size(); i++)
  9.         {
  10.             Object o =newlist.get(i);
  11.             if(!List.contains(o))
  12.                 List.add(newlist.get(i));
  13.         }
  14.         return List;
  15.     }
  16.     public static void main(String[] args)
  17.     {
  18.         Scanner read = new Scanner(System.in);
  19.          int posnbmax=0 , nbmax=0 ,nblettre=0,nbmax2=0,posnbmax2=0,difference=0,tentative=0;// mot ayant le meme nombre de lettre ;
  20.          char LettreE,lettrefreq,restart;
  21.          boolean afficherTous = false;
  22.          ArrayList<Character> lettre = new ArrayList<Character>();
  23.          ArrayList<Character> text_lettre = new ArrayList<Character>();
  24.         // ArrayList<Integer> nb_lettre = new ArrayList<Integer>();
  25.          System.out.println("rentrez votre texte en appuyant sur entré lorsque vous avez fini");
  26.          String texte = read.nextLine();
  27.          boolean test = false ;
  28.          int nb_charact = texte.length();
  29.          for(int i = 0 ; i<nb_charact ; i++)
  30.             text_lettre.add(i,texte.charAt(i));
  31.          lettre = antidoublon(text_lettre);
  32.          
  33.          //////////////////////////////////////////////
  34.          //cette partie du code va analiser la frequence des lettre codé
  35.          //////////////////////////////////////////////
  36.          for (int i =0 ;i < lettre.size() ;i++)
  37.           {
  38.              
  39.              for (int ii =0 ;ii<text_lettre.size() ;ii++)
  40.              {
  41.                 test = lettre.get(i)==text_lettre.get(ii);
  42.                
  43.                 if(test)
  44.                    nblettre++;
  45.              }
  46.              if(nblettre>nbmax)
  47.              {
  48.                  posnbmax = i;
  49.                  nbmax = nblettre;
  50.              }      
  51.              else if (nblettre > nbmax2)
  52.              {
  53.                  posnbmax2 = i;
  54.                  nbmax2 = nblettre;
  55.              }  
  56.              //nb_lettre.add(i,nblettre);
  57.              nblettre = 0;
  58.           }
  59. //////////////////////////////////////////////
  60. //cette partie du code va s'occuper de donner la difference avec la lettre la plus commune , la deuxieme ou donner l'ordre de tous afficher
  61. //////////////////////////////////////////////
  62.          do
  63.          {
  64.              if(tentative == 0) {
  65.              System.out.println("rentrez la lettre la plus utilisé ");
  66.              lettrefreq= read.nextLine().charAt(0);
  67.              LettreE = lettre.get(posnbmax);
  68.              difference = (int)LettreE-(int)lettrefreq;
  69.              }
  70.              else if (tentative == 1)
  71.              {
  72.                  System.out.println("rentrez la deuxieme lettre la plus utilisé ");
  73.                  lettrefreq= read.nextLine().charAt(0);
  74.                  LettreE = lettre.get(posnbmax2);
  75.                  difference = (int)LettreE-(int)lettrefreq;
  76.              }
  77.              else
  78.              {
  79.                  afficherTous=true;
  80.              }
  81.              tentative++;
  82.              System.out.println(difference);
  83.              do
  84.                 {
  85.                     System.out.println("voulez vous recommencer y/n?");
  86.                     restart = read.next().charAt(0);
  87.                     read.nextLine();
  88.                 }while (restart != 'y' && restart !='n' );
  89.             }while(restart == 'y' && tentative!=2);
  90.              
  91.          read.close();
  92.  
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement