Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 3.1 Create a class containing a method name createArray and a main method. The method createArray creates an array where each element contains

imageimageimageimageimage

Question 3.1 Create a class containing a method name createArray and a main method. The method createArray creates an array where each element contains the square of its index. The size of the array is determined by the method's parameter. createArray then returns this array. The main methods calls createArray with the right parameter to get the squares of the numbers from 0 to 12, it then prints the values of the array. public class Q3_SquareArray{ public static int[] createArray(int size) { } // Your code here public static void main(String[] args) { // Your code here } |} The output should be similar to this: The output should be similar to this: The square of 0 is: 0 The square of 1 is: 1 The square of 2 is: 4 The square of 3 is: 9 The square of 4 is: 16 The square of 5 is: 25 The square of 6 is: 36 The square of 7 is: 49 The square of 8 is: 64 The square of 9 is: 81 The square of 10 is: 100 The square of 11 is: 121 The square of 12 is: 144 Question 3.2 Complete this code so that it calculates the average of the 7 numbers passed via the array valuesArray: public class Q3_AverageDemo{ public static void main(String[] args) { } double[] valuesArray; valuesArray = new double[]{100.0,34.0, 72.0,56.0,82.0,67.0,94.0}; System.out.println("The average is: + calculate Average (valuesArray)); //method that calculates the average of the numbers in an array public static double calculateAverage (double[] values) { double result; //your code here return result; } Question 3.3 Create a method that inserts an element to a specific index of an array. This method has three parameters: an array, an index and a number to insert. Use the main method to print the array before and after the insertion. (Hint: arrays have fixed size; you must create a second array that is bigger than the first) public class Q3_ArrayInsertionDemo{ public static int[] insert IntoArray(int[] beforeArray, int indexToInsert, int val // Your code here } public static void main(String[] args) { } // Your code here Example of the output: Array before insertion: 1 5 7 9 96 6 Array after insertion of 15 at position 3: 1 5 5 4 15 7 9 6 Question 3.4 Complete this code so that it prints the letters from the char array unordered Letter in decreasing order: public class Q3_ReverseSortDemo { public static void main(String[] args) { } char[] unordered Letters; unordered Letters = new char[]{'b', 'm', 'z', 'a', 'u'}; reverseSort (unordered Letters); for (int i = 0; i < unordered Letters.length; i++ ) System.out.print (unordered Letters[i]); //method that sorts a char array into its reverse alphabetical order public static void reverseSort (char[] values) { //your code here } }

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

Data Structures and Algorithms in Java

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

6th edition

1118771334, 1118771338, 978-1118771334

More Books

Students also viewed these Programming questions