2
I need to make a code that:
- List a number of numbers
- Inform if they are divisible by 3 and 5
- Whether they are even or odd
- And then take the separate average of each (average of odd and average of even)
I wrote a code, but when it goes to perform the average calculation, it is giving error.
Follows code:
public class Exe_04 {
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
System.out.println("Informe a quantidade de numeros a serem listados.");
int cp = ler.nextInt();
float mediaPar, mediaImpar;
int contPar = 0, contImpar = 0;
int num[] = new int[cp];
for (int i = 0; i < num.length; i++) {
System.out.println("Digite o " + (i + 1) + "° numero: \n");
num[i] = ler.nextInt();
if ((num[i] % 3 == 0) && (num[i] % 5 == 0)) {
System.out.println("Este numero é divisivel por 3 e 5.");
}
if (num[i] % 2 == 0) {
System.out.println("Este numero é PAR.");
contPar++;
} else {
System.out.println("Este numero é IMPAR.");
contImpar++;
}
}
mediaPar = contPar / num[cp];
mediaImpar = contImpar / num[cp];
System.out.println("A media dos numeros PARES é : " + mediaPar);
System.out.println("A media dos numeros IMPARES é : " + mediaImpar);
}
}
Thanks Maniero for the help in the code and the tips, I’m new in java yet, but I will improve more my syntax and logic.
– WillGreco
@Willgreco see the best way to say thank you on the [tour].
– Maniero