1
- Make a java program do the following:
a) Fill the array with the heights of 30 individuals;
b) View the array;
c) Using the array, calculate and print the average of all the heights in the array’s indeces pairs;
d) Using the array, calculate and print the average of all times in odd indeces of the array.
e) find and print the highest and lowest individual. I tried to do so:
import java.util.Scanner;
public class Array02 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int nrIndividuos = 6;
int[] alturas = new int[nrIndividuos];
for (int i = 0; i < nrIndividuos; i++) {
System.out.println("Introduza a altura do " + (i + 1) + " individuo");
alturas[i] = s.nextInt();
}
int soma = 0;
double mediaPar = 0;
for(int j = 0; j < nrIndividuos; j++){
if(alturas[j]%2==0){
soma = soma + alturas[j];
mediaPar = soma/nrIndividuos;
}
}
System.out.println(mediaPar);
}
}
What is your doubt?
– tvdias