Baixe o app para aproveitar ainda mais
Prévia do material em texto
import java.util.Random; public class Main { import java.util.Random; public class Matriz { public static void main(String[] args) { int tam=10; int matriz [][]= new int[tam][tam]; int l,c; int padrao=0; int cont=0; l=0; c=0; for ( l=0;l<tam;l++){ for (c=0;c<tam;c++){ Random rand= new Random(); matriz[l][c]=rand.nextInt(2); } } for (l=0;l<tam;l++) { for (c=0;c<tam;c++) { if (matriz[l][c] == 1 && matriz[l][c + 1] == 1 && matriz[l+1][c]==0) { cont++; padrao+= cont; } } } System.out.println(padrao); } } }
Compartilhar