📄 occurrencesofdigit.java
字号:
import javax.swing.JOptionPane;
public class OccurrencesOfDigit{
public static void main (String[] args){
String s= JOptionPane.showInputDialog(null,"Enter the string please!","Occurrences of digits",JOptionPane.QUESTION_MESSAGE);
int[] count = count (s);
for (int j = 0;j<=9;j++){
if (count[j]==0||count[j]==1)
System.out.println(j+ " occurred " +count[j]+" time");
else
System.out.println(j+ " occurred " +count[j]+" times");
}
}
public static int[] count(String s){
int[] counts = new int[10];
for (int i = 0;i< s.length();i++ ){
if (s.charAt(i)<='9'&&s.charAt(i)>='0')
counts[s.charAt(i)-'0']++;
}
return counts;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -