Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.school;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int arr[] = new int[20];
- for (int i = 0; i < 20; i++) arr[i] = (int)Math.ceil/*Округление в большую сторону*/(Math.random/*Случайное число*/() * 10 - 5); // Генерация случайных чисел в заданном диапазоне
- int c1 = 0, c2 = 0, c3 = 0;
- // Расчет кучи разных счетчиков
- for (int i = 0; i < 20; i++) {
- if (arr[i] < 0) c1 += 1;
- if (arr[i] == 0) c2 += 1;
- if (arr[i] > 0) c3 += 1;
- }
- System.out.println("(x<0): " + c1 + " (x==0): " + c2 + " (x>0): " + c3);
- for (int i = 0; i < 20; i++) System.out.print(arr[i] + " ; ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement