0
package ifal2;
import java.util.Scanner;
public class Lista3Questao4 {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
int idade=0, contM=0, contF=0;
double soma=0, somaaltura=0, somaM=0, percentual=0, altura;
String sexo;
for(int x=0; x < 3; x++) {
System.out.println("Digite o sexo: ");
sexo = entrada.next();
System.out.println("Digite a idade: ");
idade = entrada.nextInt();
System.out.println("Digite a altura: ");
altura = entrada.nextDouble();
soma = soma + idade;
if (sexo == "1") {
somaM = somaM + idade;
contM++;
}
if (sexo == "0") {
somaaltura = somaaltura + altura;
contF++;
}
somaM = somaM/contM;
somaaltura = somaaltura/contF;
if (idade >= 18 && idade <= 35) {
percentual = percentual + idade;
}
}
System.out.println("Média da idade (geral) " + (soma/3));
System.out.println("Média da altura (feminino) " + (somaaltura));
System.out.println("Média da idade (masculino) " + (somaM));
System.out.println("Percentual de pessoas com idade entre 18-35 anos: " + (percentual/3));
}
}
A survey was made among the 1000 inhabitants of a region to collect the following data: sex (0-female, 1-male), age and height. make an algorithm that reads the collected information and shows the following information:
a) mean age of the group; OK*
b) average height of women; OK*
c) average age of men; OK*
d) percentage of persons aged between 18 and 35 (including)
I’m not getting the average age and height. Letter "d" too.
I put three in the repeating frame just to make it easier.
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero