国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

一個字母頻率分析計算小程序

2019-11-18 11:19:49
字體:
來源:轉載
供稿:網友

在密碼學中有個簡單的分析密碼的方法,就是計算每個字母出現的頻率,這個小程序就是計算輸入字符串中每個字母出現的次數的,我現在初學java,我將把我平時的小練習發到這里,用來自勉和初學者共同學習進步.高手不要見笑.
//6.7.5
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Analyser
{
    PRivate String Words;
    public Analyser (String input)//構造方法,把輸入的密碼全部轉換為大寫字母
    {
        words = input.toUpperCase();
    }
    public int getNum()//返回密碼的長度
    {
        return words.length();
    }
    public int result(char c)//方法:計算在密碼中character c出現的次數
    {
        String temp=new String(words);
        int index=temp.indexOf(c);
        int n=0;
        while(index>=0)
        {
            temp=temp.substring(index+1,temp.length());
            index=temp.indexOf(c);
            n++;
        }
            return n;
    }
    public static void main(String[] args)//主方法
    {
        System.out.print("Please input the words:");//輸入passwd
        String inputLine;
        try{
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            inputLine = in.readLine();

        }catch(Exception exc)
        {
            System.out.println("Sorry,please input a string,thx");
            return;
        }
       
        Analyser word=new Analyser(inputLine);//用類生成一個對象word
        int[] num = new int[26];//定義一個字母,用來裝A-Z26個字母
        int i;
        char ch='A';
        for (i=0;ch<91;ch++,i++)//計算每個字母在passwd出現的次數
            num[i]=word.result(ch);
        System.out.println("The passwd you input is : "+inputLine);//輸出
        System.out.println("The length of the passwd is : "+word.getNum());//輸出輸入密碼長度
        for (i=0,ch='A';i<26;ch++,i++)//輸出每個字母出現的次數
            System.out.println("The num "+ch+" has presented : "+num[i]);
    }
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 什邡市| 上蔡县| 闽清县| 大余县| 雅安市| 马鞍山市| 四会市| 大石桥市| 上思县| 集贤县| 宜良县| 新宾| 泽州县| 沭阳县| 泗洪县| 迭部县| 伊通| 水富县| 东源县| 临沂市| 高邮市| 台江县| 大田县| 怀安县| 许昌市| 加查县| 英超| 郎溪县| 孝感市| 博白县| 祁阳县| 永福县| 四子王旗| 上杭县| 常德市| 平邑县| 漯河市| 金沙县| 宁武县| 治县。| 江山市|