Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import java.io.*;
  2. class Media
  3. {
  4. public static void main (String args[])
  5. {
  6. InputStreamReader input = new InputStreamReader(System.in);
  7. BufferedReader tastiera = new BufferedReader(input);
  8.  
  9. int s=0;
  10. System.out.println("Quanti numeri vuoi inserire?");
  11. try{
  12. String val= tastiera.readLine();
  13. int n= Integer.parseInt(val);
  14. }
  15. catch(Exception e)
  16. {
  17. return;
  18. }
  19. for(int i=0;i<n;i++)
  20. {
  21. System.out.println("Inserisci valore numero: " + i);
  22. try{
  23. String val= tastiera.readLine();
  24. int num= Integer.parseInt(val);
  25. }
  26. catch(Exception e)
  27. {
  28. return;
  29. }
  30. s=s+num;
  31. }
  32. float m= s/n;
  33. System.out.println("La media vale: " + m);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement