PAT个位数统计

import java.awt.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String string=scanner.nextLine();
int num[]=new int[10];
for (int i = 0; i < num.length; i++) {
num[i]=0;
}
String string2;
for (int i = 0; i < string.length(); i++) {
string2=string.substring(i,i+1);
for (int j = 0; j < num.length; j++) {
if (string2.equals(String.valueOf(j))) {
num[j]++;
}
}

        //System.out.println(string2);
    }
    for (int i = 0; i < num.length; i++) {
        if (num[i]!=0) {
            System.out.println(i+":"+num[i]);
        }
    }
     
}

}

猜你喜欢

转载自blog.csdn.net/qq_29380377/article/details/85920006
今日推荐