Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( 1 Mark ) At the beginning of the main method initialize an empty array of 1 0 integers. ( 2 Marks ) Fill in

(1 Mark) At the beginning of the main method initialize an empty array of 10 integers.
(2 Marks) Fill in the logic for the fillRandom method. This method should fill in your array
with random integers in the range 1,100.
(1 Mark) Write the logic for the swapElements method. This method will accept an array
and two indexes. It will then swap the elements at those two indexes.
(3 Marks) Write the logic for the reverseArray method. This method should reverse the
order of the elements in your array. You must use your swapElements method.
(3 Marks) Write the logic for the shuffleArray method. This method should iterate over your
array and randomly swap each element with another element in the array. Use your
swapElements method. file: import java.util.Arrays;
import java.util.Random;
/**
* A basic intro to working with arrays.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Lab01
{
public static Random r = new Random(20240112);
public static void swapElements(int[] array, int indexA, int indexB){
// Swap the elements at 2 positions in a given array
}
public static void fillRandom(int[] array){
// Fill an array with random integers
}
public static void shuffleArray(int[] array){
// Shuffle the array
}
public static void reverseArray(int[] array){
// Reverse a given array
}
public static void main(String[] args){
// Initialize array
// Declare your integer array called array here
System.out.println(Arrays.toString(array));
// Fill the array
fillRandom(array);
System.out.println(Arrays.toString(array));
// Reverse the array
reverseArray(array);
System.out.println(Arrays.toString(array));
// Shuffle the array
shuffleArray(array);
System.out.println(Arrays.toString(array));
}
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

Let f(x|θ) be the logistic location pdf

Answered: 1 week ago