Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

must be in java: Create a class named ArrayPractice Create an instance variable named numbers. It should be an array that holds 20 integers. Create

must be in java:

Create a class named ArrayPractice

Create an instance variable named numbers. It should be an array that holds 20 integers.

Create a constructor that initializes numbers. The heading should look like this public ArrayPractice(int[] num)

Create a method called printForward. In the method using println print the line: This prints the array forward. This method should then print the array from the beginning (first element) to the end (last element). Use print and print a space between each element. Use the enhanced for loop to print the array.

Create a method called printBackward. In this method using println, print the line: This prints the line backward. Use print and print the array from the end (last element) to the beginning (first element). Print all elements on one line with a space between each element. You can use any type loop you want.

Create a method called printOdd. In this method using println print the line: This prints the odd index variables, and then use print and print every element at an odd index. You may use any type loop you want.

Create a method called printEven. In this method using println, print the line: This prints the odd index values and the use print to print every element at an even index. You may use any type loop you want. Print all elements on one line with a space between each element.

Create a method called printFirstAndLast. In this method using println, print the line: This prints the first and last elements of the array. Print the first element in the array and the last element in the array on one line using print.

Create a method called addOne. Using a loop, add 1 to each element in the array and then call the method printForward. printForword().

Create a ArrayPracticeTester.

Import java.util.Randon;

Create an integer array named values. It should hold 20 values.

Create a random number generator by typing. Random generator = new Random();

Create a loop you choose the type. You will fill the array from random numbers generated. Your numbers will be between 1 and 100. Inside the loop put code to put a random number in the array. Use this code: values[i] = 1+ generator.nextInt(100);

After you have filled the array, create an ArrayPractice object. Put the array name in the argument. ArrayPractice ap=new ArrayPractice(values);

Call each of the method in the class, ArrayPractice.

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions