Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ackage minil; _mport java.util.Scanner; ** * Utility class with some static methods involving loops. */ ublic class WackyLoops{ /** * Determines how many iterations

image text in transcribedimage text in transcribedimage text in transcribed

ackage minil; _mport java.util.Scanner; ** * Utility class with some static methods involving loops. */ ublic class WackyLoops{ /** * Determines how many iterations of the following operation are required until * the condition (a* a + b*b) > 4 is reached: * * *newA = a*ab*b+x * newB * * * newB = 2 *a*b+y a = newA b = newB * * where a and b are initially zero. If the condition (a*a+b*b) > 4 is *not reached within maxIterations , the method returns * maxIterations . * * @param x given x value * @param y given y value * @param maxIterations maximum number of iterations to attempt * @return number of iterations required to get (a a+b*b) > 4, or maxIterations * */ public static int findEscapeCount (double x, double y, int maxIterations) { } /** * Counts the number of positions in a pair of strings that have matching * characters. The strings need not be the same length. For example, *countMatches ("abcde", "xbydzzzzz") returns 2. * * @param s any string * @param t any string * @return number of positions in which the characters match in the two strings */ public static int countMatches (String s, String t) { } /** * Determines whether the two given strings are permutations (rearrangements) of * each other. The method is case sensitive. For example, * * isPermutation ("abcabc", "baaccb") returns true * isPermutation ("abc", "cbba") returns false * isPermutation ("Abc", "abc") returns false * * * @param s given string * @param t given string * @return true if the given strings are permutations of each other, false otherwise */ PARIS ELFI M MA public static boolean is Permutation (String s, String t) { } /*** *Returns a new string in which all consonants in the given string are doubled. *Consonants that are already doubled are not doubled again. For example, * doubleConsonants ("rabbit") returns "rrabbitt". It is assumed that in the *given string is alphabetic and that no character appears more than twice in a * row. *. * @param s given string * @return new string with all consonants doubled .*/ public static String doubleConsonants (String s) { } private static boolean is Vowel(char ch) { return "aeiouAEIOU".indexOf(ch) >= 0; } * Returns the second largest number in a string of integers. For example, given *the string "42 137 7 42 66 55" the method returns 66. Note that the second * largest value may be the same as the largest, e.g., for the string "5.5.5.3" * the method returns 5. If the given string is invalid or contains fewer than * two numbers, the behavior of this method is undefined. *. * @param nums string of text containing integers separated by one or more *********** spaces * * @return second largest number in the given string */ public static int find Second Largest(String nums) { } /** * Determines whether the string target occurs as a substring of * string source where "gaps" are allowed between characters of * target . That is, the characters in target occur in * source in their given order but do not have to be adjacent. * (Pictured another way, this method returns true if target could * be obtained from source by removing some of the letters of * source .) This method is case sensitive. For example, * * containsWithGaps ("hamburgers", "mug") returns true * containsWith Gaps ("hamburgers", "burrs") returns true * containsWithGaps ("hamburgers", "hamburgers") returns true * containsWithGaps (" hamburgers", "gum") returns false * containsWith Gaps ("hamburgers", "hamm") returns false * containsWithGaps ("hamburgers","") returns true * * * @param source the given string in which to find the target characters * @param target the characters to be found * @return true if the characters in target can be found as a subsequence in source , false otherwise * .*/ public static boolean substringWith Gaps (String source, String target) { } If you are working on findSecondLargest, can you a. Parse a given string into a sequence of integers. Numbers in a String can be scanned via java.util.Scanner and obtained through the nextInt API one at a time. For example: String nums = "12 34 -56 77 0"; Scanner in = new Scanner (nums); int num1 = in.nextInt(); // 12 int num2 = in.nextInt (); // 34 Return the largest number in a string of integers Return the second largest number in a string of integers. Consider whether additional variables need to be employed. If you are working on substringWithGaps, can you b. a. Return the index of the first char in the source string that matches a given target char. Loop through the chars in the target string. Use each of the chars as a target for the problem above. c. Do the same. But instead of checking the source string from the beginning, start from an char that one position over the one that matches the previous target character. d. Return false if no matching character is found by the end of the source string. Otherwise, return true. b. c.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Numerical Methods With Chemical Engineering Applications

Authors: Kevin D. Dorfman, Prodromos Daoutidis

1st Edition

1107135117, 978-1107135116

More Books

Students also viewed these Programming questions

Question

What are the major sources of change requests?

Answered: 1 week ago

Question

What are conversion costs? What are prime costs?

Answered: 1 week ago