Advertisement
knyazer

Untitled

Oct 15th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package com.school;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.  
  10.         int arr[] = new int[20];
  11.  
  12.         for (int i = 0; i < 20; i++) arr[i] = (int)Math.ceil/*Округление в большую сторону*/(Math.random/*Случайное число*/() * 10 - 5); // Генерация случайных чисел в заданном диапазоне
  13.  
  14.         int c1 = 0, c2 = 0, c3 = 0;
  15.        
  16.         // Расчет кучи разных счетчиков
  17.         for (int i = 0; i < 20; i++) {
  18.             if (arr[i] < 0) c1 += 1;
  19.             if (arr[i] == 0) c2 += 1;
  20.             if (arr[i] > 0) c3 += 1;
  21.         }
  22.  
  23.         System.out.println("(x<0): " + c1 + " (x==0): " + c2 + " (x>0): " + c3);
  24.  
  25.         for (int i = 0; i < 20; i++) System.out.print(arr[i] + " ; ");
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement