Write the method rotateRight that takes an array of integers and rotates the contents of the array to the right by two slots. Numbers that fall off the right should cycle back to the left. For example, if the input array a {1, 3, 5, 7} then the rotated array should be {5, 7,1, 3}. If the input array a {1, 2, 3} then the rotated array should be {2, 3,1}.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with Python (3rd Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Programming in C
Starting Out with Java: Early Objects (6th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- For Beginners Java: Write a program that ask the user to enter a list of positive scores until the user enters a negative score to terminate the input. You need to store these scores in an array. You can assume the maximum number of scores the user may enter is 50. However, you need to keep track of the actual number of scores entered. Write 2 methods: 1. calculateAverage(): this method takes the list of scores and return the average score. 2. countPerfectScores(): this method takes the list of scores and return the number of perfect scores (100). The main program reads the input and calls these methods and print the results. Please make sure you write a comment line to document what your method does.arrow_forwardWrite the following methodarrow_forwardIn Pythonarrow_forward
- A void method creates an integer array of size 12. The method then ask user to input these 12 numbers and store them in the array. Then print out all the numbers that are multiples of 3 and then print out all the numbers that are multiples of 4. Example: Input a number (1/12): 3 Input a number (2/12): 5 Input a number (3/12): 7 Input a number (4/12): 8 Input a number (5/12): 2 Input a number (6/12): 3 Input a number (7/12): 10 Input a number (8/12): 6 Input a number (9/12): 2 Input a number (10/12): 7 Input a number (11/12): 12 Input a number (12/12): 9 The multiples of 3 are: 3, 3, 6, 12, 9 The multiples of 4 are: 8, 12arrow_forwardCan you write code according to the desired conditions ?arrow_forwardWrite a program that declares an array of 15 integers and reads the values from the user. Make sure that the user doesn’t enter a value greater than 10 (if the user enters a value not in the allowed range, discard that value and read another to put into the array). Now tell the number that occur maximum number of times in the array. For example for the following 7 has maximum occurrence. 4,7,3,3,2,7,1,5,7,9,9,9,7,8,10 Use both linear and binary search.arrow_forward
- Write a method that takes two arrays as parameters. It should return a new array where each position has the sum of the two corresponding positions in the two incoming arrays. The returned array should be as long as the longer of the two passed in arrays.arrow_forwardWrite a method to read numbers from the keyboard into an array. Stop reading when the user enters the sentinel value -999. Return the number of values that were read. Do not put the sentinel in the array and do not include it in the number of values entered. Print an error message and stop reading if the user tries to enter more values than the array can hold.Write a method to print out the numbers in the array. Make sure the method only prints the array positions that were filled with the user's input. Print one number on each line.Write a method called zeros to return the number of entries in the array which contain zero.Write a method called replace which includes the parameters before and after, which are both integers. The method will change every array entry that contains the value before to contain the value after. For example, if the array contains {10,20,30,40,20,50}, before is 20 and after is 1, the array should be changed to {10,1,30,40,1,50}.Write a method called positive…arrow_forwardProblem: Write a method that will determine whether a given value can be made given an array of coin values. For example, each value in the array represents a coin with that value. An array with [1, 2, 3] represents 3 coins with the values, 1, 2, and 3. Determine whether or not these values can be used to make a desired value. The coins in the array are infinite and can only be used as many times as needed. Return true if the value can be made and false otherwise. Dynamic Programming would be handy for this problem. Data: An array containing 0 or more coin values and an amount. Output: Return true or false. Sample Data ( 1, 2, 3, 12, 5 ), 3 ( 4, 15, 16, 17, 1 ), 21 ( 1 ), 5 ( 3 ), 7 Sample Output true true true falsearrow_forward
- Write a Java application to insert 10 items (integers) in the array by user input. Write followingmethods to solve the problem. a. Write Separate method Input array itemsb. Write Separate method Pass the full array into a method and calculate the smallestitem and return it to the method from where the method was calledc. Write a Separate method to pass the array and return how many items are there in thearrayd. Write a Separate method to pass the array and return the average of the arrayarrow_forwardJavaarrow_forwardWrite a program that prompts the user for an integer, then asks user to enter that many integer value. Store these values in an integer array and print the array. Reverse the array elements so that first element become the last element, the second element become the second to last element, and so on, with the old last element now first. Do not just reverse the order in which they are printed; actually, change the way they are stored in the array. Try not to create a second array; just rearrange the elements within the array you have. (Hints; Swap elements that need to change place.) When the elements have been reversed, Print the array again.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education