Use any loops in Java Language
Write the method named withoutString().
*
* Given two strings, base and remove, return a
* version of the base string where all instances
* of the remove string have been removed (not case
* sensitive). You may assume that the remove
* string is length 1 or more. Remove only non-overlapping
* instances, so with "xxx" removing "xx" leaves "x".
*
* Note: Despite the term "remove" you should actually not
* try to remove the characters from a string. You'll continue
* to use the "building a string" pattern from lecture.
*
* Examples:
* withoutString("Hello there", "llo") returns "He there"
* withoutString("Hello there", "e") returns "Hllo thr"
* withoutString("Hello there", "x") returns "Hello there"
*
* @param base the base String to modify.
* @param remove the substring to remove.
* @return the base String with all copies of remove removed.
*/
// TODO - Write the withoutString method here
/**
* Write the method named sameEnds().
*
* Given a string, return the longest substring
* that appears at both the beginning and end of
* the string without overlapping. For example,
* sameEnds("abXab") should return "ab".
*
* Examples:
* sameEnds("abXYab") returns "ab"
* sameEnds("xx") returns "x"
* sameEnds("xxx") returns "x"
*
* @param str the String to search.
* @return the longest substring that appears at beginning and end.
*/
// TODO - Write the sameEnds method here.
/**
* Write the method named maxBlock().
*
* Given a string, return the length of the
* largest "block" in the string. A block is a run
* of adjacent characters that are the same.
*
* Examples:
* maxBlock("hoopla") returns 2
* maxBlock("abbCCCddBBBxx") returns 3
* maxBlock("") returns 0
*
* @param str the String to examine.
* @return the size of the longest run of adjacent characters.
*/
// TODO - Write the maxBlock method here.
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images
- Complete 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_forwardJava - Insect Growtharrow_forwardWrite a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 import java.util.Scanner; public class CourseGradePrinter {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);final int NUM_VALS = 4;int [] courseGrades = new int[NUM_VALS];int i; for (i = 0; i < courseGrades.length; ++i) {courseGrades[i] = scnr.nextInt();} /* Your solution goes here */ P.S. The answer came out wrong the first try 7 9 11 10 10 11 9 7Enterarrow_forward
- can you plz write it in java.util.scanner formarrow_forwardGiven a long string use recursion to traverse the string and replace every vowel (A,E,I,O,U) with an @ sign. You cannot change the method header. public String encodeVowels(String s){ // Your code here }arrow_forwardWith Java, use single, two-way and multi-way if statements to write different kinds of loops that process Strings.arrow_forward
- Please dont copy and paste previous solutions. I checked them they are wrong.arrow_forwardRevorse the vewels def reverse_vowels(text): Given a text string, create and return a new string constructed by finding all its vowels (for simplicity, in this problem vowels are the letters found in the string 'aeiouAEIOU') and reversing their order, while keeping all other characters exactly as they were in their original positions. However, to make the result look prettier, the capitalization of each moved vowel must be the same as that of the vowel that was originally in the target position. For example, reversing the vowels of 'Ilkka' should produce 'Alkki' instead of 'alkkI'. Applying this operation to random English sentences seems to occasionally give them a curious pseudo-Mediterranean vibe.Along with many possible other ways to perform this square dance, one straightforward way to reverse the vowels starts with collecting all vowels of text into a separate list, and initializing the result to an empty string. After that, iterate through all positions of the original text.…arrow_forwardIntegers numberOfParts, required Groups, and invalid Groups are read from input. If numberOfParts is 21 or more, then add 3 to requiredGroups. Otherwise, add 6 to invalidGroups. ► Click here for examples 3 public class GroupSurvey { 4 public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int numberOfParts; int requiredGroups; I int invalidGroups; 345679 8 9 10 11 12 13 14 15 16 17 18 19 20 } numberOfParts = scnr.nextInt (); requiredGroups = scnr.nextInt (); invalidGroups = scnr.nextInt (); /* Your code goes here */ if(numberOfParts>21){ requiredGroups= System.out.println(requiredGroups); System.out.println(invalidGroups);arrow_forward
- def findOccurrences(s, ch): lst = [] for i in range(0, len(s)): if a==s[i]: lst.append(i) return lst Use the code above instead of enumerate in the code posted below. n=int(input("Number of rounds of Hangman to be played:")) for i in range(0,n): word = input("welcome!") guesses = '' turns = int(input("Enter the number of failed attempts allowed:")) def hangman(word): secrete_word = "-" * len(word) print(" the secrete word " + secrete_word) user_input = input("Guess a letter: ") if user_input in word: occurences = findOccurrences(word, user_input) for index in occurences: secrete_word = secrete_word[:index] + user_input + secrete_word[index + 1:] print(secrete_word) else: user_input = input("Sorry that letter was not found, please try again: ") def findOccurrences(s, ch): return [i for i, letter in enumerate(s) if letter == ch] *** enumerate not discussed in…arrow_forwardIn Java (Use the isPrime Method) PrimeNumberMethod.java, provides the isPrime(int number) method for testing whether the number is prime. Use this method to find the number of prime numbers less than 10000. Below are some clarifications for the Java program (a) The lab is to COUNT the prime numbers less than 10000. Do NOT list the prime numbers. (b) A pair prime is two prime numbers whose difference is 2. For e.g. 3,5; 11,13; 17, 19; etc. We can use IsPrime function to count how many pair primes are there in a range from 2 to 100 for example. Create a function pairPrime, that takes one argument. pairPrime should return the number of pair primes between 2 and the argument passed. Use the pairPrime function to count the pair primes between 2 and 1000. Make use of the IsPrime function to solve this task. (This feature is worth 8 points). Use the compile/run button to test tour program. Include the output displayed. It will be similar to: command>javac…arrow_forwardFor java. Refer to picture.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