Answer Key
University
California State UniversityCourse
COMP 122 | Computer Architecture and Assembly Language and LabPages
2
Academic year
2022
NyiH
Views
13
public class COMP_122 { public static void main(String[] args) { int[] arr = {21, 30, 25, 35, -16}; int total = 0; int negativeNum = 0; for(int i = 0; i < arr.length; i++) { total += arr[i]; if(arr[i] < 0) negativeNum++; } System. out .println("The average is " + total/arr.length); System. out .println("The number of negative numbers is " + negativeNum); } }
Calculating Average and Counting Negative Numbers in Java Array
Please or to post comments