1
I’m new to Java and found this problem:
Given a character array ('.' or '#'), your task is to specify the the size of the largest contiguous segment (horizontal or vertical) of characters '#'
This is my code so far:
import java.util.*;
import java.lang.*;
public class Counting{
    public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    int l = in.nextInt();
    int c = in.nextInt();
    Matrix m = new Matrix(l,c);
    m.ler(in); //ler matriz
    int valor = m.output(m);
    System.out.println(valor);
    }
}
class Matrix {
    char data[][]; //elementos da matriz
    int lin; //nr de linhas
    int col; //nr de colunas
    //construir matriz
    Matrix(int l, int c){
    data = new char[l][c];
    lin = l;
    col = c;
    }
    //ler Matriz
    public void ler(Scanner in){
    for(int i=0;i<lin;i++){
        String c = in.next();
        for(int j=0;j<col;j++){
        data[i][j] = c.charAt(j);
        }
    }
    }
    public int output(Matrix h){
    int linha=0;
    int coluna=0;
    int maior_tamanho=0;
    int maior_tamanhol=0;
    int maior_tamanhoc=0;
    for(int i=0;i<h.lin;i++){
         if(maior_tamanhol<=linha)
        maior_tamanho=linha;        
        linha=0;
        if(maior_tamanhoc<=coluna)
        maior_tamanhoc=coluna;
        coluna=0;    
        for(int j=0;j<h.col;j++){
        if(h.data[i][j]=='#'){
            linha++;
        }
        if(h.data[j][i]=='#'){
            coluna++;
        }
        }
    }
    if(maior_tamanhol>=maior_tamanhoc)
        maior_tamanho=maior_tamanhol;
    else
        maior_tamanho=maior_tamanhoc;
    return maior_tamanho;
    }
}
For input:
3 3
#..
##.
.#.
It gives the right output, which is two:
2
But with this input:
4 8
.....#..
##...#..
.#..###.
####.#..
Give me this mistake:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
    at Matrix.output(Counting.java:67)
    at Counting.main(Counting.java:11)
Can anyone help me? Thank you