Program
class Assignment
{
//method to return a String contains all the
characters
//that consists of both the String inputs
public static String stringsConsists(String s1, String
s2)
{
//base condition
if(s1.length()==0 ||
s2.length()==0)
return "";
//extract first character
char c = s1.charAt(0);
//check if c is found in the String
s2
if(s2.contains(""+c))
return ("" + c +
stringsConsists(s1.substring(1), s2));
//if c is found in the String
s2
return
(stringsConsists(s1.substring(1), s2));
}
//main method
public static void main (String[] args)
{
String s1 = "fourth";
String s2 = "faster";
String s3 = stringsConsists(s1,
s2);
System.out.println(s3);
}
}
Output:
frt
N.B. Whether you face any problem then share with me in the comment section, I'll happy to help you.
recursively take two strings that are NOT THE SAME and return the string that consists of...
recursively take two strings that are NOT THE SAME and return the string that consists of all the letters that appear in both string1 and string2 using only string1 and string2 as inputs with NO LOOPS. This must be done recursively. for example, if string1 is "fourth" and string2 is "faster" the string returned is "frt"
using c and pointers only 1. You will read in two strings from a file cp4in_1.txt at a time (there will be 2n strings, and you will read them until EOF) and then do the following. You alternately take characters from the two strings and string them together and create a new string which you will store in a new string variable. You may assume that each string is no more than 20 characters long (not including the null terminator),...
containsSubSequence takes two Strings as input and returns a boolean: Returns true if the first input string contains all the characters of the second input string, in order, but not necessarily consecutively. > HW2.containsSubSequence("abracadabra", "abcd") true > HW2.containsSubSequence("abracadabra", "abdc") false you must not use either break or continue in your code. You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method I write something...
In pyhton 3.7 please 2. Write a function that takes, as an argument, either a 12-digit positive integer n or a string consisting of 12 digits, and calculates the 13th digit (the check digit) for a 13-digit ISBN. Name this function calculateCheckDigit(n). For example, >>>calculateCheckDigit(452678904653) should return 5. As an additional example, >>>calculateCheckDigit(546654945486) should return 8. 3. Write a function that takes, as an argument, an eight-bit binary string and does the following, in this order: • Verifies that it...
Write a method will accept an array of Strings. This method should return the string that comes after all the other strings in lexicographical order. (Assume all the Strings only contain lower case letters. In Example: No number, no Capitals and no Symbols) lastString({“hola”, “word”, “night”, “boom”}) → “word” lastString({“java”, “is”, “so”, “much”, “fun”}) → “so” lastString({“i”, “love”, “java”}) → “love” //precondition: words.length >0 public static String lastString(String[] words) { }
Write a function addStrings(string1, string2) that takes in two decimals as strings and returns a string of their sum. *Simply converting strings to numbers and adding them together isn’t acceptable.* The program must be able to handle large decimals. Be sure to touch on these when solving for the solution: Pad the right side Pad the left side Make sure string is same length by putting 0’s where it was missing (be careful w/ decimal points) Make sure to remove...
Programming language: Java m: substring length n: input strings d: Hamming distance (mismatch) I: Number of letters in Sample input string (s1, s2, s3) Strings consists of: A, C, G, and T Example outputs: Generate all possible possibilities of length m(4) using the values A, C, G, and T. EX possibilites: {A,A,A,A A,A,A,C.... G,G,G,G} and find all the possible combinations that have the same sequence with a hamming distance of 1 (only 1 difference) Given n input strings of length...
Which of the following functions will take a vector of strings and return a list of integers containing the sizes of the strings without using any loops or recursion? For example, when provided a vector v0 with the strings ["abc", "", "defg", "h"], the function f(v0) should return a list of integers [3,0,4,1]. A. std::list<size_t> f(const std::vector<std::string>& v0) { std::list<size_t> result; for (std::vector<std::string>::iterator it = v0.begin(), it != v0.end(), it++) { result.push_back((*it).size()); } return result; } B. std::list<size_t> f(const std::vector<std::string>&...
Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-') to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are...
JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...