Question

In: Computer Science

This program needs to be in Java Exercise on Single Dimensional Arrays Declare an array reference...

This program needs to be in Java


Exercise on Single Dimensional Arrays

  1. Declare an array reference variable arrayInt for an array of integers. Create the array of size 100, and assign it to arrayInt. (2 points)
  2. Write a method to populate the array with Random numbers between 1 to 25. Signature of the method is: populateArray( int[] ) which returns nothing. Call this method from main with arrayInt--> populateArray(arrayInt). (2 points)
  3. Write a method to print an array. Signature of the method is: printArray( int[] ) which returns nothing. Print maximum of ten(10) numbers on a line (see sample output below). Call this method from main with arrayInt--> printArray(arrayInt). Hint: Use the modulus operator. Any number n % 10 will return a value 0-9. (3 points)
  4. Write a method that finds the average of the array elements. Signature of the method is: findAverage( int[] ) which returns the averageto the calling program.Call this method from main with arrayInt--> findAverage(arrayInt).  (3 points)

SAMPLE OUTPUT:

1   12 20  11  10  15  17   5  20   8  
23 6 4 20 23 15 15 24 4 19
3 10 15 12 8 5 23 24 2 25
2 19 13 3 7 22 17 8 15 9
22 17 3 5 5 20 24 19 21 13
9 1 16 5 16 8 24 11 7 1
19 16 14 11 23 22 23 25 18 3
16 3 10 3 17 15 3 17 15 17
22 16 16 7 15 7 10 22 10 1
21 20 18 4 11 24 24 2 19 12
The average is: 12.51

Solutions

Expert Solution

JAVA Program:

import java.io.*;
import java.util.*;
public class Main
{
public static void populateArray(int []arrayInt){
Random rand=new Random();
for(int i=0;i<100;i++)
arrayInt[i]=rand.nextInt(25)+1;
}
  
public static void printArray(int []arrayInt){
int i=0;
while(i<100){
System.out.print(arrayInt[i]+" ");
i++;
if(i%10==0)
System.out.println();
}
}
  
public static float findAverage(int []arrayInt){
float total=0;
for(int i=0;i<100;i++)
total+=arrayInt[i];
return total/100;
}
  
   public static void main(String[] args) {
       int[] arrayInt = new int[100];
       populateArray(arrayInt);
       printArray(arrayInt);
       System.out.printf("The average is: %.2f",findAverage(arrayInt));
   }
}

Output:


Related Solutions

Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array which can store up to 50 student names where a name is up to 25 characters long - an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array which can store up to 50 student names where a name is up to 25 characters long - an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
1.Declare a two-dimensional array of Strings namedchessboard.
1. Declare a two-dimensional array of Strings named chessboard.2. Declare a two-dimensional array of integers named tictactoe.3. Declare and create a two-dimensional array of chars,tictactoe, with 3 rows, each with 3 elements.4. Create a two-dimensional array of ints, plan, with 2 rows, and and 3 columns and initialize the first row to 8, 20, 50 and the second row to 12, 30, 75. Use member initializer syntax.
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT