Advertisement
G_Burlakova

Задача_Работници2

Nov 25th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 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.  
  7. package kontrolno3;
  8. import java.util.Scanner;
  9. /**
  10.  *
  11.  * @author Gaby
  12.  */
  13. public class Kontrolno3 {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {
  19.         Scanner sc = new Scanner(System.in);
  20.         System.out.println("Въведи брой служители");
  21.         int num = sc.nextInt();
  22.         int sumOdd = 0;
  23.         int sumBelow = 0;
  24.         while (num < 0){
  25.             System.out.println("Въвели сте отрицателен брой служители.\nМоля въведете положителен такъв");
  26.             num = sc.nextInt();
  27.         }
  28.         int arrayEmp [] = new int [num];
  29.         for (int i = 0; i < arrayEmp.length; i++) {
  30.             System.out.println("Въведи възрастта на служител № " + (i + 1));
  31.             arrayEmp [i] = sc.nextInt();
  32.             while (arrayEmp [i] < 16 || arrayEmp [i] > 65){
  33.                 System.out.println("Въвели сте грешна стойност за възрастта");
  34.                 System.out.println("Въведи възрастта на служител № " + (i + 1));
  35.                 arrayEmp [i] = sc.nextInt();
  36.             }
  37.              if ((i + 1) % 2 != 0){
  38.                  sumOdd = sumOdd + arrayEmp [i];
  39.              }
  40.              if(arrayEmp [i] < 55){
  41.                  sumBelow = sumBelow + arrayEmp [i];
  42.              }
  43.         }
  44.         System.out.println("Сумата на възрастите на служителите с нечетен номер е: " + sumOdd);
  45.         System.out.println("Сумата на възрастите на служителите под 55 е: " + sumBelow);
  46.     }
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement