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 kontrolno3;
- import java.util.Scanner;
- /**
- *
- * @author Gaby
- */
- public class Kontrolno3 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Въведи брой служители");
- int num = sc.nextInt();
- int sumOdd = 0;
- int sumBelow = 0;
- while (num < 0){
- System.out.println("Въвели сте отрицателен брой служители.\nМоля въведете положителен такъв");
- num = sc.nextInt();
- }
- int arrayEmp [] = new int [num];
- for (int i = 0; i < arrayEmp.length; i++) {
- System.out.println("Въведи възрастта на служител № " + (i + 1));
- arrayEmp [i] = sc.nextInt();
- while (arrayEmp [i] < 16 || arrayEmp [i] > 65){
- System.out.println("Въвели сте грешна стойност за възрастта");
- System.out.println("Въведи възрастта на служител № " + (i + 1));
- arrayEmp [i] = sc.nextInt();
- }
- if ((i + 1) % 2 != 0){
- sumOdd = sumOdd + arrayEmp [i];
- }
- if(arrayEmp [i] < 55){
- sumBelow = sumBelow + arrayEmp [i];
- }
- }
- System.out.println("Сумата на възрастите на служителите с нечетен номер е: " + sumOdd);
- System.out.println("Сумата на възрастите на служителите под 55 е: " + sumBelow);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement