1题:
请统计出下面的数据块中有多少个1?
10111000100110010111110111000101100100011001100110
00100101100010100101101000101011101000011010010001
10010001101100010001001111101000011001011011010110
01011101011110101110101111010100010001111100000000
11101110101100101100100101010011101101111110100101
10010111000000101111100010011100100101110100101000
10010001000110101011000011111001110110101010111101
01101000100000111010001110001101111101000001000011
01001010001011100100110010111111100110111100010000
10000001011000000011000110110101010111100011000000
11010100101101110000000110110011111000100010011110
10101101101001011101100011011111111101100100010000
00101000100000000101000100101011001111000100111011
10100111011101100010101000111111001010000100111111
01111010100001100010011011100010111001111001010001
01100011100111000010100000011101100001001000010001
00000001111001000111010010001101101110110110100000
00000001110111101010011111110000110101100001111101
11100100111110100101100110010111100011111011111000
10010101101111011011011111101000111011000010111001
当然,我们不反对你一行一行地人工数出来,但这很容易出错啊。这么机械的事情为什么不交给计算机帮你呢?
可以把这些数据做成一个常量串,然后逐一枚举每个字符,遇见是1的就计数吧!
祝你好运!
注意:只需要填写一个整数,不要填写任何多余的内容。比如说明文字。
private static int count;
public static void main(String[] args) {
String x="10111000100110010111110111000101100100011001100110\r\n" +
"00100101100010100101101000101011101000011010010001\r\n" +
"10010001101100010001001111101000011001011011010110\r\n" +
"01011101011110101110101111010100010001111100000000\r\n" +
"11101110101100101100100101010011101101111110100101\r\n" +
"10010111000000101111100010011100100101110100101000\r\n" +
"10010001000110101011000011111001110110101010111101\r\n" +
"01101000100000111010001110001101111101000001000011\r\n" +
"01001010001011100100110010111111100110111100010000\r\n" +
"10000001011000000011000110110101010111100011000000\r\n" +
"11010100101101110000000110110011111000100010011110\r\n" +
"10101101101001011101100011011111111101100100010000\r\n" +
"00101000100000000101000100101011001111000100111011\r\n" +
"10100111011101100010101000111111001010000100111111\r\n" +
"01111010100001100010011011100010111001111001010001\r\n" +
"01100011100111000010100000011101100001001000010001\r\n" +
"00000001111001000111010010001101101110110110100000\r\n" +
"00000001110111101010011111110000110101100001111101\r\n" +
"11100100111110100101100110010111100011111011111000\r\n" +
"10010101101111011011011111101000111011000010111001";
char[] q=x.toCharArray();
for (int i = 0; i < q.length; i++) {
if (q[i]=='1') {
count++;
}
}
System.out.println(count);
}
结果为:497
网友评论