Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class HelloWorld
  5. {
  6.  
  7.      public static void main(String []args)
  8.      {
  9.         float srednia = 0;
  10.         if(args.length < 2 || args.length > 10)
  11.         {
  12.             throw new IllegalArgumentException("Zła ilosc danych!");
  13.         }
  14.         else
  15.         {
  16.             try
  17.             {
  18.                 for(int i = 0; i < args.length ; i++)
  19.                 {
  20.                     srednia += Float.parseFloat(args[i]);
  21.                 }
  22.                
  23.                 srednia = srednia / args.length;
  24.                
  25.                 System.out.println(srednia);
  26.                
  27.             }
  28.             catch(Exception e)
  29.             {
  30.                 throw new IllegalArgumentException("Niepoprawny typ danych!");
  31.             }
  32.         }
  33.      }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement