Nesse codigo para percorrer uma matriz 49x49 (que pode não estar totalmente preenchida), e calcular medias, da erro de exceção: java.lang.ArithmeticException: / by zero
Como trato este problema?
public void imprimirresultado()
{
int mulherdoente=0;
int mulhersadia=0;
int totalmulher=0;
int homemdoente=0;
int homemsadio=0;
int totalhomem=0;
int mediaMsadia=0;
int mediaMinfect=0;
int mediaHsadio=0;
int mediaHinfect=0;
int mediaPsadias=0;
int mediaPinfect=0;
for (int l=0; l<mat.length ; l++)
{
for (int c=0; c<mat.length ; c++)
{
if ( (mat[l][c]!=null) && (mat[l][c].getSexo()=='f') )
{
if (mat[l][c].getDoente()==true)
{
mulherdoente+=1;
totalmulher+=1;
}
else if (mat[l][c].getDoente()==false)
{
mulhersadia+=1;
totalmulher+=1;
}
}
if ( (mat[l][c]!=null) && (mat[l][c].getSexo()=='m') )
{
if (mat[l][c].getDoente()==true)
{
homemdoente+=1;
totalhomem+=1;
}
else if (mat[l][c].getDoente()==false)
{
homemsadio+=1;
totalhomem+=1;
}
}
}
}
mediaMsadia= ((mulhersadia/totalmulher)*100);
mediaMinfect= ((mulherdoente/totalmulher)*100);
mediaHsadio= ((homemsadio/totalhomem)*100);
mediaHinfect= ((homemdoente/totalhomem)*100);
mediaPsadias= ((mulhersadia+homemsadio)/(totalmulher+totalhomem)*100);
mediaPinfect=((mulherdoente+homemdoente)/(totalmulher+totalhomem)*100);
System.out.println
- o System.out.println eu tirei ai pq era muito grande, mas basicamente mostra todas as variaveis de media
valeu