Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package zad1;
- import java.util.Scanner;
- import java.util.Random;
- public class Zad1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner scan= new Scanner(System.in);
- Random los=new Random();
- System.out.println("Ile liczb podac ?");
- int ile=scan.nextInt();
- if(ile>=2 && ile<=10)
- {
- float[] a=new float[ile];
- for(int i=0; i<ile; i++)
- {
- a[i]=los.nextFloat()%100.0f;
- System.out.print(a[i]+" ");
- }
- System.out.printf("\nSrednia %d liczb wynosi %f",ile,srednia(a));
- }
- else
- {
- System.out.println("\nWprowadz wiecej niz 2 i mniej niz 10 liczb !");
- }
- }
- public static float srednia(float[] tab)
- {
- float srednia=0,suma=0;
- for(int i=0; i<tab.length ; i++)
- {
- suma+=tab[i];
- }
- srednia=suma/tab.length;
- return srednia;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement