Advertisement
Guest User

zad 1

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 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 zad1;
  7.  
  8. import java.util.Scanner;
  9. import java.util.Random;
  10. public class Zad1 {
  11.  
  12. /**
  13. * @param args the command line arguments
  14. */
  15. public static void main(String[] args) {
  16. Scanner scan= new Scanner(System.in);
  17. Random los=new Random();
  18.  
  19. System.out.println("Ile liczb podac ?");
  20. int ile=scan.nextInt();
  21. if(ile>=2 && ile<=10)
  22. {
  23. float[] a=new float[ile];
  24. for(int i=0; i<ile; i++)
  25. {
  26. a[i]=los.nextFloat()%100.0f;
  27. System.out.print(a[i]+" ");
  28.  
  29. }
  30.  
  31.  
  32. System.out.printf("\nSrednia %d liczb wynosi %f",ile,srednia(a));
  33. }
  34. else
  35. {
  36. System.out.println("\nWprowadz wiecej niz 2 i mniej niz 10 liczb !");
  37. }
  38.  
  39. }
  40.  
  41. public static float srednia(float[] tab)
  42. {
  43. float srednia=0,suma=0;
  44. for(int i=0; i<tab.length ; i++)
  45. {
  46. suma+=tab[i];
  47. }
  48. srednia=suma/tab.length;
  49. return srednia;
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement