I’m studying Java basics from the beginning. But there is still some theoretical basis.
How do I calculate the average of each student in the example below?
package teste01classes;
public class Metodos {
static void Media(Alunos[] aluno) {
// SEE HERE.
double[] media;
for (int i = 0; i < aluno.length; i++) {
media[i] = (aluno[i].n1 + aluno[i].n2 + aluno[i].n3) / 3;
System.out.println(aluno[i].nome + media[i]);
}
}
}
package teste01classes;
// Classe Alunos com os campos
public class Alunos {
String nome;
int n1, n2, n3;
}
package teste01classes;
public class Teste01Classes {
public static void main(String[] args) {
Alunos[] aluno = DadosAlunos.createAlunos();
}
}
You have to initialize the
mediaarray, and thenreturnit:Then, in your
main, invoke it: