Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make changes in the java file according to the instruction to complete the task. Instructions : a . ( 1 Mark ) At the beginning

Make changes in the java file according to the instruction to complete the task. Instructions : a.(1 Mark) At the beginning of the main method initialize an empty array of 10 integers.
b.(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].
c.(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.
d.(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.
e.(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. javaFile : import java.util.Arrays;
import java.util.Random;
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));
}
}

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

Step: 3

blur-text-image

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

plan how to achieve impact in practice from your research;

Answered: 1 week ago