import java.util.Random;
public class IntegerToBinary {
public static void main(String[] args) {
Random rnd = new Random();
int a = rnd.nextInt();
String b=Integer.toBinaryString(a); //将整数转化为二进制数.
System.out.println(b);
int i = numVowels(b,"1");
System.out.println(i); //打印出1的个数.
}
public static int numVowels(String a,String vowels) {
int result = 0;
for( int i = 0; i < a.length(); i++ ) {
if( vowels.indexOf( a.charAt( i ) ) != -1 ) {
result++;
}
}
return result;
}
}