Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) Create a class Homework (in a file Homework.java) b) Create a static method initializeArray that receives as a parameter an array of integers. Use

a) Create a class Homework (in a file Homework.java) b) Create a static method initializeArray that receives as a parameter an array of integers. Use a for loop and an if statement to put 5s in the odd positions of the array and 0s in the even positions. c) Create a static method printArray that receives as a parameter an array of integers. Use a for statements to print all the elements in the array. d) Create a static method selectionSort that receives as a parameter an array of integers and order its element in descending order. Implement Selection Sort algorithm. It should be Selection Sort, not Bubble Sort, not Quick Sort, etc. If you do not remember selection sort, this link could be useful: https://goo.gl/hrAdMo e) Create a static recursive method that calculate and returns the factorial a number. The method receives the number (integer number) as parameter f) Copy the following main method in your class, public static void main (String [] arg) { int [] a = {3, 5, 6, 8, 12, 13, 16, 17, 18, 20}; int [] b = {18, 16, 19, 3 ,14, 6}; int [] c = {5, 2, 4, 3, 1}; // testing initializeArray printArray(a); // print: 3, 5, 6, 8, 12, 13, 16, 17, 18, 20 initializeArray(a); printArray(a); // print: 0, 5, 0, 5, 0, 5, 0, 5, 0, 5 // testing initializeArray printArray(b); // print: 18, 16, 19, 3 ,14, 6 selectionSort (b); printArray(b); // print: 19, 18, 16, 14, 6, 3 // testing factorial System.out.println (factorial (5)); //print: 120 c[0] = factorial (c[0]); c[1] = factorial (c[2]); printArray(c); // print: 120, 24, 4, 3, 1 }

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

=+2 Why did OBI create Centers of Excellence?

Answered: 1 week ago

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago