在一个9位整数n(=123456789)中,把它的各位上的数都按素数,合数,其它归类,并用五角星表示各类数出现的频度。输出结果:素数:★★★★合数:★★★★其它:★publicclasssuhe{p...
在一个9位整数n(=123456789)中,把它的各位上的数都按素数,合数,其它归类,并用五角星表示各类数出现的频度。
输出结果:
素数:★★★★
合数:★★★★
其它:★
public class suhe{
public static void main(String[] args){
int n=123456789,su=0,he=0,qita=0,a;
for(int i=100000000; i>=1; i/=10){
a=n/i;
n-=a*i;
for(int b=2;b<=a-1;b++){
if(a==2){su++;
break;}
else if(a%b==0){
he++;break;}
else if(b==a-1){
su++;break;}
else{
qita++;
break;
}
}
System.out.print("素数:");
for(int su1=su;su1>=1;su1--)System.out.print("★");
System.out.println();
System.out.print("合数:");
for(int he1=he;he1>=1;he1--)System.out.print("★");
System.out.println();
System.out.print("其它:");
for(int qita1=qita;qita1>=1;qita1--)System.out.print("★");
System.out.println();
}
}
展开