?? lettercounting.java
字號(hào):
import javax.swing.*;
public class LetterCounting {
public static final int LETTERNUMBER=26;
public static void main(String args[]){
//提示用戶輸入
String s = JOptionPane.showInputDialog(null,"輸入一個(gè)字符串:"
,"示例輸入",JOptionPane.QUESTION_MESSAGE);
//invoking the count letters method to count each lettr.
int []numberUpper=countUpper(s);
int []numberLower= countLower(s);
//decare and initialize the output string.
String output = "";
//display the result.
for(int i=0;i<numberUpper.length;i++){
if(numberUpper[i]!=0) output+=(char)('A'+i)+" 出現(xiàn)在 "+ "次數(shù)\n";
}
for(int i=0;i<numberLower.length;i++){
if(numberLower[i]!=0) output+=(char)('a'+i)+" 出現(xiàn)"+"次數(shù)\n";
}
JOptionPane.showMessageDialog(null,output,"示例輸出",JOptionPane.INFORMATION_MESSAGE);
}
public static int[] countUpper(String s){
int []count = new int[LETTERNUMBER];
for(int i=0;i<s.length();i++){
if(Character.isUpperCase(s.charAt(i)))
count[(int)(s.charAt(i)-'A')]++;
}
return count;
}
public static int[] countLower(String s){
int []count = new int[LETTERNUMBER];
for(int i=0;i<s.length();i++){
if(Character.isLowerCase(s.charAt(i)))
count[(int)(s.charAt(i)-'a')]++;
}
return count;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -