Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Уймин Максим
- //IT School, 2 группа
- //09.10.2015
- //Задача 6. Подсчитать количество положительных и отрицательных чисел в массиве
- import java.io.PrintStream;
- import java.util.Scanner;
- public class Exersise_6 {
- public static PrintStream out = System.out;
- public static Scanner scan = new Scanner(System.in);
- public static int[] CreateArray (int N){
- //Функция создаёт массив и заполняет его случайными числами
- int[]array = new int[N];
- out.println("Original array:");
- for (int i=0;i<N;i++){
- array[i]=(-10) + (int)(Math.random()*((10-(-10))+1));
- out.print(array[i]+" ");
- }
- out.println();
- return array;
- }
- public static void CountElements (int[] array,int N){
- //Функция считает количество положительных и отрицательных чисел
- int pos = 0;
- int neg = 0;
- for (int i=0;i<N;i++){
- if (array[i]>0) pos++;
- if (array[i]<0) neg++;
- }
- out.println("There are "+pos+" positive numbers and there are "+neg+" negative numbers");
- }
- public static void MainFunction (){
- //Здесь собран весь функционал программы
- out.println("Enter the array size(intger number, greather then zero)");
- int N = scan.nextInt();
- int[] array=new int [N];
- array = CreateArray(N);
- CountElements(array, N);
- }
- public static void main (String [] args){
- //Основная функция, отсюда начинается выполнение приложения
- MainFunction();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement