Write a recursive method that takes two strings str and forbidden and removes all characters from the forbidden string from str.
JAVA
import java.util.Scanner;
/**
* A recursive method that removes forbidden characters from a string.
*/
public class CleanUp
{
public static String clean(String str, String forbidden)
{
/* Your code goes here */
if (forbidden.contains(first))
{
return /* code goes here */
}
else
{
return /* code goes here */
}
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while (in.hasNext())
{
String str1 = in.next();
String str2 = in.next();
System.out.println(clean(str1, str2));
}
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Complete this code/** * Remove adjacent duplicate characters in a string. * For example, delDuplicate("aaabbc") → "abc". * @param input is the input string. * @return the resulting string. */public static String delDuplicate(String input) { // base case // recursive step }arrow_forwardWrite a java program with a method that reverses a string The method must accept one parameter of type String (string to reverse), and returns every second element from the end to the beginning. For example: String: thisisstringResult is: g i t s s harrow_forwardWarmup Write a method called countSuit) that takes an array of Cards and a String suit as parameters and counts how many of the cards have the given suit. Complete the definition of the class Warmup and method definition countSuit shown below. public class Warmup { public static int countSuit(Card [] cards, String suit) { // fill in code here } } For example, if we ran the following code in the main method: Card[] cards = new Card[4]; cards [0] = new Card (4, "clubs"); cards [1] = new Card (12, "diamonds"); cards [2] = new Card (1, "hearts"); cards [3] new Card(10, "diamonds"); System.out.println(countSuit(cards, "diamonds")); the output printed would be 2.arrow_forward
- How do I make the code output Java? import java.util.Arrays; public class Movie { String movieName; int numMinutes; boolean isKidFriendly; int numCastMembers; String castMembers[] = new String[10]; // Non-parameterized constructor public Movie() { this.movieName = "Flick"; this.numMinutes = 0; this.isKidFriendly = false; this.numCastMembers = 0; } // Parameterized constructor public Movie(String movieName, int numMinutes, boolean isKidFriendly, int numCastMembers, String[] castMembers) { this.movieName = movieName; this.numMinutes = numMinutes; this.isKidFriendly = isKidFriendly; this.numCastMembers = numCastMembers; this.castMembers = castMembers; } // getter and setters public String getMovieName() { return movieName; } public void setMovieName(String movieName) { this.movieName = movieName; } public int getNumMinutes() { return numMinutes; } public void setNumMinutes(int numMinutes) { this.numMinutes = numMinutes; } public boolean isKidFriendly() { return…arrow_forwardSolve in javaFXarrow_forwardComplete this codeYou can write a recursive helper method that takes any number of arguments and then call it inside the method, but you cannot use any loops. /** * Decide if it is possible to divide the integers in a list into two sets, * so that the sum of one set is odd, and the sum of the other set is a multiple of 10. * Every integer must be in one set or the other. * For example, oddAndTen([5, 5, 3]) → true, * and oddAndTen([5, 5, 4]) → false. * @param list is a list of integers. * @return true iff there is one odd partition and the other multiple of 10. */public static boolean oddAndTen(List<Integer> list) { // call your recursive helper method return ...} private static boolean oddAndTenHelper(...) { // add any parameters // base case // recursive step}arrow_forward
- Java - Insect Growtharrow_forwardCode 16-1 /** This class has a recursive method. */ public class EndlessRecursion { public static void message() { System.out.println("This is a recursive method."); message(); } } Code 16.2 /** This class has a recursive method message, which displays a message n times. */ public class Recursive { public static void messge (int n) { if (n>0) { System.out.println (" This is a recursive method."); message(n-1); } } } Task #1 Tracing Recursive Methods 1. Copy the file Recursion.java (see Code Listing 16.1) from the Student Files or as directed by your instructor. 2. Run the program to confirm that the generated answer is correct. Modify the factorial method in the following ways: a. Add these lines above the first if statement: int temp; System.out.println("Method call -- " + "calculating " + "Factorial of: " + n); Copyright © 2019 Pearson Education, Inc., Hoboken NJ b. Remove this line in the recursive section at the end of the method: return…arrow_forwardWrite an application that displays the strings in the provided array alphabetically in ascending order. import java.util.*; public class StringSort { publicstaticvoidmain(String[] args) { String[] values = {"mouse","dog","cat","horse","cow", "moose","tiger","lion","elephant","bird","hamster", "guinea pig","leopard","aardvark","hummingbird"}; }arrow_forward
- TASK 3 The String class is provided in the Java library. Provide your own Java implementation for the following methods (name the new class MyString): public Mystring(char [] chars); public char charat (int index); int length(); public Mystring substring(int begin, int end); public Mystring toLowercase); public boolean equals (Mystring s); public static Mystring valueof (int i); public int compare(string s); public Mystring substring(int begin); public Mystring toupperCase(); Write a Java test program that tests all methods in the class.arrow_forwardWrite a recursive function that returns the largest integer in a list. Write a test program that prompts the user to enter a list of integers and displays the largest element.arrow_forwardUse Javaarrow_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