⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex7_5.java

📁 判断三角形
💻 JAVA
字号:
//7.5 统计字符串中字母的个数
public class Ex7_5{
  public static void main (String[] args) {
     String str="SSN is 343 32 4545 an ID is 434 34 4323";
     int[] countofstr=count(str);
     for(int i=0;i<=9;i++)
     System.out.println(i+"的次数为:"+countofstr[i]);
  }
  public static int[] count (String s){
  	 int[] countofnum=new int[10];
     for(int i=0;i<s.length();i++){
       if(s.charAt(i)<=57&&s.charAt(i)>=48){
       int j=s.charAt(i);
       countofnum[j-48]++;//利用数字的ASCII码值确定对应下标
       }
     }
     return countofnum;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -