Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package circuitobioquímicodigital;
- import java.util.Scanner;
- public class CBD {
- private boolean[][] matriz;
- private int[] matriz_a;
- private int p, m;
- Scanner scan;
- CBD(int p, int m) { // p = pontos = colunas | m = medições = linhas
- matriz = new boolean[m][p + 1];
- matriz_a = new int[p + 1];
- for(int i = 0; i < p; i++)
- matriz_a[i] = 0;
- scan = new Scanner(System.in);
- this.p = p;
- this.m = m;
- }
- public void lerCBD() {
- System.out.println("Insira, linha por linha, o CBD:");
- for(int i = 0; i < this.m; i++) {
- for(int j = 0; j < this.p; j++) {
- int temp = scan.nextInt();
- if(temp == 1)
- matriz[i][j] = true;
- else if(temp == 0)
- matriz[i][j] = false;
- else {
- System.out.println("Valor inválido! Definido para 1.");
- matriz[i][j] = true;
- }
- }
- }
- }
- public void calcularSaida() {
- boolean anterior = false;
- for(int i = 0, temp = 0; i < this.p; i++) {
- for(int j = 0; j < this.m; j++) {
- if(matriz[j][i]) {
- temp++;
- anterior = true;
- }
- if(j + 1 == this.m || (!matriz[j][i] && anterior)) {
- matriz_a[temp]++;
- System.out.println(temp);
- anterior = false;
- temp = 0;
- }
- }
- }
- }
- public void printarSaida() {
- System.out.println("\n\n" + this.toString() + "\nForam encontrados:");
- for(int i = 0; i <= this.m; i++)
- if(matriz_a[i] != 0 && i != 0)
- System.out.println(matriz_a[i] + " palito(s) de comprimento " + i);
- }
- @Override
- public String toString() {
- String field = "";
- for(int i = 0; i < this.m; i++) {
- for(int j = 0; j < this.p; j++) {
- if(matriz[i][j])
- field += "1 ";
- else
- field += "0 ";
- }
- field += "\n";
- }
- return field;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement