Concept explainers
(Occurrences of a specified character in an array) Write a recursive method that finds the number of occurrences of a specified character in an array. You need to define the following two methods. The second one is a recursive helper method.
public static int count(char[] chars, char ch)
public static int count(char[] chars, char ch, int high)
Write a test
Want to see the full answer?
Check out a sample textbook solutionChapter 18 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: Early Objects (6th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Python (4th Edition)
Starting Out with Python (3rd Edition)
C++ How to Program (10th Edition)
- 1) Write a method that returns the range of an array of integers. The range is the difference between the highest and lowest values in the array. The signature of the method should be as follows. public static int computeRange(int[] values)arrow_forwardWrite a program to accomplish the following tasks:- a) Write a method to print the ArrayList in the reverse order b) Write a method to sort the ArrayList, and display the data after sorting c) Write a method to print the largest and the smallest element in the ArrayList d) In the main method ask user to enter 10 integers, store them in the ArrayList, pass the ArrayList to above methods, and then display the result after each call.arrow_forward6arrow_forward
- Write pseudocode that will a.) initialize an array with 5 values and declare a second empty array of the same size. b.) copy the contents of the first array into the second array. (Hint: use a loop.) Java 1 public class FinalGrade2 {3 public static void main(String args[])4 {5 //variable declarations and initialization6 String studentName = "Nicholas Simoneaux";7 final double QUIZ_PERCENTAGE = 0.5;8 final double TEST_PERCENTAGE = 0.5;910 double quizOne = 98.5;11 double quizTwo = 77.0;12 double quizAverage;13 double testOne = 85.0;14 double testTwo = 67.0;15 double testAverage;16 double extraCredit = 10.0;17 double finalGrade;1819 //calculations20 quizAverage = quizOne + quizTwo / 2;21 testAverage = testOne + testTwo / 2;2223 finalGrade = (quizAverage * QUIZ_PERCENTAGE) + (testAverage * TEST_PERCENTAGE) + extraCredit; 24 25 //output26 System.out.println("Student…arrow_forwardTASK 1 Write a Java method that returns the index of the smallest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: public static int indexofLargestlestelement(double[] array) Write a test program that prompts the user to enter ten numbers, invokes this method to return the index of the smallest element, and displays the index.arrow_forwardWrite method body of following methods: DeleteNum(int position) // This method will delete element from array at position entered by the user arrange the data after that position to left. (Using While loop) DeleteNum(int from, int to) // This method will delete elements from array at range given by the user, as the user inputs two positions i.e start and end, the program should than delete all numbers in that range. (Use C++ to code)arrow_forward
- please code in python Forbidden concepts: arrays/lists (data structures), recursion, custom classes You have been asked to take a small icon that appears on the screen of a smart telephone and scale it up so it looks bigger on a regular computer screen.The icon will be encoded as characters (x and *) in a 3 x 3 grid as follows: (refer image1 ) Write a program that accepts a positive integer scaling factor and outputs the scaled icon. A scaling factor of k means that each character is replaced by a k X k grid consisting only of that character. Input Specification:The input will be an integer such that 0 < k ≤ 10. Output Specification:The output will be 3k lines, which represent each individual line scaled by a factor of k and repeated k times. A line is scaled by a factor of k by replacing each character in the line with k copies of the character. [refer image2]arrow_forwardJava Programming [ Using Array] - 1arrow_forwardJava Programming [ Using Array] - 3arrow_forward
- Question 3 : (Eliminate duplicates) Write a program Duplicate.java that reads in ten integers in an array T, creates a new array V by eliminating the duplicate values in the array, and displays the result. Here is the sample run of the program: Enter ten numbers: 1 2 3 2 1 6 3 4 5 2 The distinct numbers are: 1 2 3 6 4 5arrow_forwardIndicate true or false for the following statements: Every element in an array has the same type. The array size is fixed after it is declared. The array size declarator must be a constant expression. The array elements are initialized when an array is declared.arrow_forwardWrite the following methodthat tests whether the array has four consecutive numbers with the same value:public static boolean isConsecutiveFour(int[] values)Write a test program that prompts the user to enter a series of integers and displaysit if the series contains four consecutive numbers with the same value. Yourprogram should first prompt the user to enter the input size—i.e., the number ofvalues in the series. Here are sample runs: Enter the number of values: 8↵EnterEnter the values: 3 4 5 5 5 5 4 5↵EnterThe list has consecutive foursEnter the number of values: 9↵EnterEnter the values: 3 4 5 5 6 5 5 4 5↵EnterThe list has no consecutive foursarrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage