Given a string of even length, return the first half. So the string "WooHoo" yields "Woo".
CodeWorkout Practice 2
Score: 0 / 62.0
Exercises
Rewrite the following for loop using a while loop.
call_a(); for(; call_b(); call_c()) call_d();
Rewrite the following do while loop using a for loop.
call_a(); do { call_c(); } while (call_b());
Rewrite the following while loop using a for loop.
call_a(); while (call_b()) call_c();
Write a function fullWords(s) that returns a string no longer than 20 characters. If the string s is longer than 20 characters, just...
Given an array of Strings, return the longest String in the array. If the array is empty, return null.
Write a function first10(s) that returns the first 10 characters of s. If s is longer than 10 characters, just truncate it. If s is...
Given an array of integers, return the largest value in the array. Assume the array has only posivitive numbers. If the array is empty,...
Write a function untilSpace(s) that returns a substring of s starting at the beginning and extending until a space is found. The space is...
This method takes an ArrayList of Strings as a parameter and returns the longest String in the list. If the list is empty, it should...
declare a variable with the appropriate data type to have a statement that says: “Good Morning.” Use the variable you created in the...
this method accepts a String object as a parameter. It returns true if the String has all unique characters, false otherwise. For...
This methods takes a String object as a parameter and returns an encrypted version of the object. The encryption is done in two steps:...
This method takes a String object as a parameter and returns a compressed version of the object. The method compresses the String by...
Complete this method to print the two String parameters combined (concatenated) together.
Complete this method to return the two String parameters combined (concatenated) together.
A sandwich is two pieces of bread with something in between. Write a Java method that takes in a string str and returns the string that...
We'll say that a string is xy-balanced if for all the 'x' characterss in the string, there exists a 'y' character somewhere later in the...
Write a function in Java that returns true if the given string str contains an occurrence of the substring "xyz" where "xyz" is not...
Given two strings, return true if either of the strings appears at the very end of the other string, ignoring upper/lower case...
Write a function in Java that counts the number of times the string "code" appears anywhere in the given string str, except that we'll...
Write a function in Java that implements the following logic: Given a string str and a non-empty word, return a string made of each...
Write a function in Java that implements the following logic: Given two strings, a and b, create a bigger string made of the first...
Write a function in Java that implements the following logic: Given a string str and a non-empty word, return a version of the original...
Write a function in Java that implements the following logic: Given a string and an int n, return a string made of n repetitions of the...
Given a string, return a string where every appearance of the lowercase word "is" has been replaced with "is not". The word "is" should...
Given a string, return the sum of the numbers appearing in the string, ignoring all other characters. A number is a series of 1 or more...
Given a string, look for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or...
Given a string, return the length of the largest "block" in the string. A block is a run of adjacent chars that are the same.
We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. Return true if all the...
We'll say that a "triple" in a string is a char appearing three times in a row. Return the number of triples in the given string. The...
Given a string, return true if the number of appearances of "is" anywhere in the string is equal to the number of appearances of "not"...
Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed (not...
Returns true if for every '*' (star) in the string, if there are chars both immediately before and after the star, they are the same.
Given a string, compute a new string by moving the first char to come after the next two chars, so "abc" yields "bca". Repeat this...
Given a string, consider the prefix string made of the first N chars of the string. Does that prefix string appear somewhere else in the...
Given a string, return a string where for every char in the original, there are two chars.
Write a method called listSearch() that takes in a target string and a list of other strings. This method returns a (possibly shorter)...
Given a string, count the number of words ending in 'y' or 'z'--so the 'y' in "heavy" and the 'z' in "fez" count, but not the 'y' in...
Given two strings, word and a separator sep, return a big string made of count occurrences of the word, separated by the separator...
Return true if the given string contains a "bob" string, but where the middle 'o' character can be any character.
Return true if the string "cat" and "dog" appear the same number of times in the given string.
Given a string, return the string made of its first two chars, so the string "Hello" yields "He". If the string is shorter than length 2,...
Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string's length will be at least 2.
...Given a string str and an int n, return a string made of the first n characters of the string, followed by the first n - 1 characters of...
Write a function in Java that implements the following logic: Given 2 strings, a and b, return a string of the form short+long+short,...
Given the following class, create a constructor that will take in one parameter for each field, and set the fields to the corresponding...
Given the following constructor, set the fields to the corresponding parameters.
Complete the function countStrings() so that it returns the count of Strings in the array names that are not null.
Complete the function countStrLongerThan() so that it returns the count of Strings in the array names that are longer than minLen. You...
In the class below, create three private fields and two public fields. The types can be any primitive, and the values can be anything.
For this problem assume you have access to a Person class. Below, you'll see the start of a Student class that is a subclass of Person....
For this problem assume you have access to a Shape class. Below, you'll see the start of a Square class that is a subclass of Shape....
For this problem assume you have access to a Person class defined here:
public class Person { private double moneyInWallet; private int...
For this question assume you are writing a method within the following class:
public class Person { private int age; public void...
For this problem you will use this class:
public class Rectangle { private int length; private int width; public void setLength(int len)...
For this question, take a look at the Ball class defined below.
public class Ball { private boolean isInflated; public Ball() {...
For this question, you are writing a method for a class Person with the following constructor (which also shows the field names):
public...
For this question, you will be working with the following two classes
A Weather class and a Person class:
public class Weather { private...
If the class Pug extends the class Dog, what can't be said about the classes?
What's wrong with the following code? Assume both the interface and class share the same package.
public interface Account { int...
There exists an abstract class Bird.
public abstract class Bird { public Bird() {} public String eat() { return "worms"; } public...