Advertisement
Tecnelm

Untitled

Nov 12th, 2017
65
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<Character> 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.     static ArrayList<String> afficherTous(String texte) {
  17.         ArrayList<String> texteTraduit = new ArrayList<String>();
  18.         String text= "";
  19.         int nb_charact = texte.length();
  20.         for(int ii =0 ; ii<=25 ; ii++)
  21.         {
  22.             for(int i = 0 ; i<nb_charact ; i++)
  23.             {
  24.              text+=(char)(texte.charAt(i)+ii);                   
  25.             }
  26.             texteTraduit.add(text);
  27.             text="";
  28.         }
  29.         return texteTraduit;
  30.              
  31.          
  32.        
  33.     }
  34.     public static void main(String[] args)
  35.     {
  36.         Scanner read = new Scanner(System.in);
  37.          int posnbmax=0 , nbmax=0 ,nblettre=0,difference=0;// mot ayant le meme nombre de lettre ;
  38.          char LettreE,lettrefreq,restart;
  39.          boolean afficherTous = false;
  40.          ArrayList<Character> lettre = new ArrayList<Character>();
  41.          ArrayList<Character> text_lettre = new ArrayList<Character>();
  42.          // ArrayList<Integer> nb_lettre = new ArrayList<Integer>();
  43.          System.out.println("rentrez votre texte en appuyant sur entré lorsque vous avez fini");
  44.          String texte = read.nextLine();
  45.          boolean test = false ;
  46.          int nb_charact = texte.length();
  47.          for(int i = 0 ; i<nb_charact ; i++)
  48.              text_lettre.add(i,texte.charAt(i));
  49.          lettre = antidoublon(text_lettre);
  50.          
  51. //////////////////////////////////////////////
  52. //cette partie du code va analiser la frequence des lettre codé
  53. //////////////////////////////////////////////
  54.          for (int i =0 ;i < lettre.size() ;i++)
  55.           {
  56.              
  57.              for (int ii =0 ;ii<text_lettre.size() ;ii++)
  58.              {
  59.                 test = lettre.get(i)==text_lettre.get(ii);
  60.                
  61.                 if(test)
  62.                    nblettre++;
  63.              }
  64.              if(nblettre>nbmax)
  65.              {
  66.                  posnbmax = i;
  67.                  nbmax = nblettre;
  68.              }      
  69.            
  70.             // nb_lettre.add(i,nblettre);
  71.              nblettre = 0;
  72.           }
  73.  
  74. //////////////////////////////////////////////
  75. //cette partie du code va s'occuper de donner la difference avec la lettre la plus commune, et redemander de tenter a chaque fois ou donner l'ordre de tous afficher
  76. //////////////////////////////////////////////
  77.          do
  78.          {
  79.              System.out.println("rentrez la lettre la plus utilisé ");
  80.              lettrefreq= read.nextLine().charAt(0);
  81.              LettreE = lettre.get(posnbmax);
  82.              difference = (int)LettreE-(int)lettrefreq;
  83.  
  84.              System.out.println(difference);
  85.              do
  86.                 {
  87.                     System.out.println("voulez vous recommencer y/n? ou afficher tous:a");
  88.                     restart = read.next().charAt(0);
  89.                     read.nextLine();
  90.                 }while (restart != 'y' && restart !='n'&& restart !='a' );
  91.              if (restart =='a')
  92.                  afficherTous = true ;
  93.             }while(restart == 'y' && !afficherTous);
  94.              
  95.          read.close();
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement