Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Liczby{
  3.     public static void main(String[] args){
  4.         Scanner sc = new Scanner(System.in);
  5.         int n = 0;
  6.         int min = 1;
  7.         boolean inputValidate = false;
  8.         do{
  9.         System.out.println("Podaj liczbe od 1 do 1000: ");
  10.         n = sc.nextInt();
  11.         if(n>=1&&n<=1000){
  12.             inputValidate = true;
  13.         }
  14.         else{
  15.             System.out.println("liczba poza zasiegiem 1 do 1000, podaj poprawna liczbe: ");
  16.         }
  17.         }while(!(inputValidate));
  18.  
  19.         System.out.println("Podaj "+n+" liczb calkowitych w zakresie od 1 do 100: ");
  20.         int liczba = 0;
  21.         float sum = 0;
  22.  
  23.         for(int i = 1; i <= n; i++){
  24.                 liczba = sc.nextInt();
  25.             if(liczba>=1&&liczba<=100){
  26.                 sum += liczba;
  27.             }
  28.             else{
  29.                 System.out.println("liczba poza zasiegiem 1 do 100, podaj poprawna liczbe: ");
  30.                 i -= 1;
  31.             }
  32.  
  33.  
  34.         }
  35.         float avg = sum/n;
  36.         System.out.println("Srednia = " + avg);
  37.         sc.close();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement