Advertisement
Jordimario

calcoli

Nov 5th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package compito4aif;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author quartaaif
  13. */
  14.  
  15. public class Calcoli {
  16. Scanner scan = new Scanner(System.in);
  17. private int i;//contatore
  18. private int[] numArr;//array di numeri
  19.  
  20. public void Immetti(){//metodo per immettere numeri
  21. System.out.println("i1mmettere lunghezza array");
  22. this.numArr = new int[scan.nextInt()];//fa scegliere all'utente la lunghezza dell'array
  23. System.out.println("inserire i numeri");
  24.  
  25. for(i=0;i<this.numArr.length;i++){//ciclo per immettere numeri
  26. this.numArr[i]=scan.nextInt();//immessione numeri array
  27. }
  28. }
  29.  
  30. public float MediaPari(){
  31. float pari=0;//somma pari
  32. float nmed=0;//numero di numeri sommati
  33. for(i=0;i<this.numArr.length;i++){
  34.  
  35. if(this.numArr[i]%2==0){//se pari veine sommato
  36. pari+=this.numArr[i];
  37. nmed++;
  38. }
  39.  
  40. }
  41. return pari/nmed;//ritorna la media senza salvare
  42. }
  43.  
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement