Write a static method removeDuplicates(Character[] in) that returns a new array of the characters in the given array, but without any duplicate characters. Always keep the first copy of the character and remove subsequent ones. For example, if in contains b, d, a, b, f, a, g, a, a, and f, the method will return an array containing b, d, a, f, and g. (Hint: One way to solve this problem is to create a boolean array of the same size as the given array in and use it to keep track of which characters to keep. The values in the new boolean array will determine the size of the array to return.)
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java : Introduction To Prob...-MyProgrammingLab
Additional Engineering Textbook Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Java How To Program (Early Objects)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Problem Solving with C++ (9th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- Write a method called kthLargest() that accepts an integer x and an array a of integers as its parameters. It should then return the elements that that k elements of greater or equal value. So if k = 0 return the largest element. If k = 1. return the second-largest element, and so on. Do not change the array itself, but you can make a copy if you want. Suggested approach make a COPY of the array. Sort the copy then find the kth element of the copy and return it. The original is left untouched! :) For example if array1 = {74, 85, 102, 99, 101, 56, 84} and the function kthLargest(2, array1) is called, then your method should return 99 because there are two values that are larger than 99. (101 and 102). If x is less than zero or greater than/equal to the the size of the array then return -9999; Make sure your main function works for the following public static void main(String[] args){int[] array1 = {6, 8, 2, 3, 5, 12, 16, 1, 7, 4, 21, 19};int answer =…arrow_forwardWrite a Java method that takes two 2 dimensional int arrays (a and b) anda 2 dimensional boolean array (c) where all three arrays have the samesize. Your method should return an array (result) such that, if a particular element in c is true, then the corresponding (same indexed) elementin result must be the multiplication of the the corresponding elements ofa and b. If the element in c is false, then the the corresponding elementin result must be the negative of multiplication of the the correspondingelement in a and b.arrow_forwardWrite the method printTail() method that accepts an array of integers and an integer index as parameters and prints all the array elements starting from the index passed. For example if printTail(x,5) is invoked, it should print all the elements of the array x starting at x[5].arrow_forward
- Use Java programming. Write the removeEvens() method, which receives an array of integers as a parameter and returns a new array of integers containing only the odd numbers from the original array. The main program outputs values of the returned array. Hint: If the original array has even numbers, then the new array will be smaller in length than the original array and should have no blank elements. Ex: If the array passed to the removeEvens() method is [1, 2, 3, 4, 5, 6, 7, 8, 9], then the method returns and the program output is: [1, 3, 5, 7, 9] Ex: If the array passed to the removeEvens() method is [1, 9, 3], then the method returns and the program output is: [1, 9, 3] import java.util.Arrays; public class LabProgram { public static int[] removeEvens(int [] nums) { /* Type your code here */} public static void main(String[] args) { int [] input = {1,2,3,4,5,6,7,8,9};int [] result = removeEvens(input); // Helper method Arrays.toString() converts int[] to a…arrow_forwardFOR JAVA // Question is the first one, try to solve it by using the second question. Repeat the second question, but if there are multiple occurrences of the number, your program must return the largest index instead of the small- est. Write a method that takes a one dimensional integer array and an integer, and returns the index of the integer in the array. If the integer is not in the array, your program must return -1. If there are multiple occurrences of that number, your program must return the smallest index.arrow_forwardWrite a method called stdev that returns the standard deviation of an array of integers. Standard deviation is computed by taking the square root of the sum of the squares of the differences between each element and the mean, divided by one less than the number of elements. (It's just that simple!) More concisely and mathematically, the standard deviation of an array a is written as follows: stdev(a)=∑i=0a.length−1(a[ i ]−average(a)2)a.length−1 For example, if the array passed contains the values [1, –2, 4, –4, 9, –6, 16, –8, 25, –10], your method should return approximately 11.237.arrow_forward
- Write a method reverse that takes an array as an argument and returns a new array with the elements in reversed order. Do not modify the array. Only edit code in the /* Your code code goes here */ portions.arrow_forwardWrite a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. import java.util.Scanner; public class ModifyArray { /* Your solution goes here */ public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int numElem = 4; int[] sortArray = new int[numElem]; int i; int userNum; for (i = 0; i < sortArray.length; ++i) { sortArray[i] = scnr.nextInt();} swapArrayEnds(sortArray); for (i = 0; i < sortArray.length; ++i) { System.out.print(sortArray[i]); System.out.print(" ");} System.out.println("");}}arrow_forwardWrite a Java program that expands a given binomial (x + y)^n, where integer n is user input. To do the work of the binomial expression, first create a method that accepts n as a parameter and then returns an array holding the coefficients needed for the binomial expansion using the Pascal’s Triangle method. Create a 2nd method which takes the array holding the coefficients as a parameter and prints the appropriate binomial expansion. For example, if n = 5 is entered by the user, the method calculating the coefficients should return {1,5,10,10,5,1} and the method that prints the expansion should print the following: (x + y)^5 = x^5 + 5x^4y + 10x^3y^2 + 10x^2y^3 + 5xy^4 + y^5 Your main method should use an appropriate loop for repeated inputs and automatically call the methods to calculate the coefficients and print the binomial expansion. There isn’t a need for a menu although you should ask the user if they want to quit or continue after their binomial expansion is printed each time.…arrow_forward
- Write a helper method, with the signature eliminateZerosinArray[int[]): int[], that takes a single dimensional int array as an argument, and returns a new array that only contains the original values that are not equal to 0. The returned array may be the same size or smaller depending on whether there are values that are equal to 0 in the original array. You may only use standard intl| arrays to solve this.arrow_forwardWrite a program with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not methodEXAMPLE OUTPUT:Enter…arrow_forwardI need to write an array method that Shift all elements to the right by one and move the last element into the first position. For example, 1 4 9 16 25 would be transformed into 25 1 4 9 16. For some reason, I managed to get it to shift to the left, but I cannot figure out to shift it to the right? The problem is from Big Java 6th E. E7.10.barrow_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