public class Main {
public static void main
(String[] args
) { int[][] img = {
{ 1, 1, 1, 1, 1, 1, 1, 1 },
{ 0, 1, 0, 1, 1, 1, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 0, 0, 1, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },};
int ppreto = 0;
int pbranco = 0;
int linhaPreta = 0;
int linhaBranca = 0;
for (int i = 0; i < img.length; i++) {
int itensPreto = 0;
int itensBranco = 0;
for (int j = 0; j < img[i].length; j++) {
if (img[i][j] == 0) {
ppreto++;
itensPreto++;
}
if (img[i][j] == 1) {
pbranco++;
itensBranco++;
}
}
if (itensPreto == img[i].length) linhaPreta++;
if (itensBranco == img[i].length) linhaBranca++;
}
System.
out.
print("qtde ponto preto = " + ppreto
+ "\n"); System.
out.
print("qtde ponto branco = " + pbranco
+ "\n"); System.
out.
print("Qtd linha preta = " + linhaPreta
+ "\n"); System.
out.
print("Qtd linha branca= " + linhaBranca
+ "\n"); }
}
//https://pt.stackoverflow.com/q/43702/101
cHVibGljIGNsYXNzIE1haW4geyAKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKCSAgICBpbnRbXVtdIGltZyA9IHsKCSAgICB7IDEsIDEsIDEsIDEsIDEsIDEsIDEsIDEgfSwKCSAgICB7IDAsIDEsIDAsIDEsIDEsIDEsIDAsIDAgfSwKCSAgICB7IDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAgfSwKCSAgICB7IDEsIDEsIDEsIDEsIDEsIDEsIDEsIDEgfSwgCgkgICAgeyAxLCAxLCAxLCAxLCAxLCAxLCAxLCAxIH0sCgkgICAgeyAxLCAxLCAxLCAxLCAxLCAxLCAxLCAxIH0sCgkgICAgeyAxLCAxLCAwLCAwLCAxLCAxLCAxLCAwIH0sIAoJICAgIHsgMCwgMCwgMCwgMCwgMCwgMCwgMCwgMCB9LH07CgkgICAgaW50IHBwcmV0byA9IDA7CgkgICAgaW50IHBicmFuY28gPSAwOwoJICAgIGludCBsaW5oYVByZXRhID0gMDsKCSAgICBpbnQgbGluaGFCcmFuY2EgPSAwOwoJICAgIGZvciAoaW50IGkgPSAwOyBpIDwgaW1nLmxlbmd0aDsgaSsrKSB7CgkgICAgCWludCBpdGVuc1ByZXRvID0gMDsKCSAgICAJaW50IGl0ZW5zQnJhbmNvID0gMDsKCSAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBpbWdbaV0ubGVuZ3RoOyBqKyspIHsKCQkgICAgICAgICBpZiAoaW1nW2ldW2pdID09IDApIHsKICAgIAkgICAgICAgICAgICAgcHByZXRvKys7CgkgICAgICAgICAgICAgICAgIGl0ZW5zUHJldG8rKzsKCSAgICAgICAgICAgIH0KCSAgICAgICAgICAgIGlmIChpbWdbaV1bal0gPT0gMSkgewoJICAgICAgICAgICAgICAgIHBicmFuY28rKzsKCSAgICAgICAgICAgICAgICBpdGVuc0JyYW5jbysrOwoJICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChpdGVuc1ByZXRvID09IGltZ1tpXS5sZW5ndGgpIGxpbmhhUHJldGErKzsKICAgICAgICAgICAgaWYgKGl0ZW5zQnJhbmNvID09IGltZ1tpXS5sZW5ndGgpIGxpbmhhQnJhbmNhKys7CgkgICAgfQoJICAgIFN5c3RlbS5vdXQucHJpbnQoInF0ZGUgcG9udG8gcHJldG8gPSAiICsgcHByZXRvICsgIlxuIik7CgkgICAgU3lzdGVtLm91dC5wcmludCgicXRkZSBwb250byBicmFuY28gPSAiICsgcGJyYW5jbyArICJcbiIpOwoJICAgIFN5c3RlbS5vdXQucHJpbnQoIlF0ZCBsaW5oYSBwcmV0YSA9ICIgKyBsaW5oYVByZXRhICsgIlxuIik7CgkgICAgU3lzdGVtLm91dC5wcmludCgiUXRkIGxpbmhhIGJyYW5jYT0gIiArIGxpbmhhQnJhbmNhICsgIlxuIik7Cgl9Cn0KCi8vaHR0cHM6Ly9wdC5zdGFja292ZXJmbG93LmNvbS9xLzQzNzAyLzEwMQ==