package myMethods;
import java.util.Scanner;
public class CalculationsOnArrays {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int x ;
System.out.println("How many numbers are in the array");
int N = input.nextInt();
int[] arr = new int [N] ;
System.out.println("Enter the numbers") ;
for (x = 0; x < N; x++) {
arr[x] = input.nextInt();
}
double average = 0 ;
int count_negative_elements = 0;
// calling method
AVER(arr, average, count_negative_elements, N, x);
input.close();
}
static void AVER(int[] arr, double average, int count_negative_numbers, int N, int x) // passing parameters to the method
{
int sum = 0, count = 0, negative_numbers = 0 ;
sum += arr[x] ;
average = sum / N;
System.out.println("The average of the numbers is " + average);
if (arr[x] < 0) {
count++ ;
negative_numbers = arr[x] ;
System.out.println("The negative numbers in the array are " + count);
System.out.println("They are " + negative_numbers) ;
}
}
}
I wanted to do some calculations on the 1D array.