Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rubrica;
- import java.util.Scanner;
- public class Rubrica {
- public static final int N = 4;
- static void leggi(int n, Studente vet[]){
- int i,j; Scanner in = new Scanner(System.in);
- for(i=0;i<n;i++){
- System.out.println("Inserisci Nome, Cognome e Voto");
- vet[i]=new Studente();
- vet[i].nome=in.nextLine();
- vet[i].cognome=in.nextLine();
- vet[i].voto=in.nextInt();in.nextLine();
- }
- }
- static float media(int n,Studente vet[]){
- int i;
- float m=0.0f;
- for(i=0;i<n;i++)
- m=m+vet[i].voto;
- return m/n;
- }
- public static void main(String[] args) {
- int i;
- Studente v[];
- v=new Studente[N];
- leggi(N,v);
- for(i=0;i<N;i++){
- System.out.print(v[i].nome+" ");
- System.out.println(v[i].cognome);
- }
- System.out.println("Voto medio: "+media(N,v));
- }
- }
- /****
- La classe studente va in un file denominato Studente.java con questo contenuto:
- package rubrica;
- public class Studente {
- String nome;
- String cognome;
- int voto;
- }
- ***/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement