Question

//USE JAVA FOR RECURSION OF FOLLOWING Ask the user to enter a word, and then send...

//USE JAVA FOR RECURSION OF FOLLOWING

Ask the user to enter a word, and then send it to a method which recursively creates a new string with an "*" place between each character. addAsterisks("welcome") → "w*e*l*c*o*m*e"

addAsterisks ("resursion") → "r*e*c*u*r*s*i*o*n"

addAsterisks(“z”) → "z"

addAsterisks ("fun") → "f*u*n

Homework Answers

Answer #1
public class AddAsterisks {

    public static String addAsterisks(String s) {
        if (s.length() <= 1) {
            return s;
        } else {
            return s.charAt(0) + "*" + addAsterisks(s.substring(1));
        }
    }

    public static void main(String[] args) {
        System.out.println(addAsterisks("recursion"));
        System.out.println(addAsterisks("z"));
        System.out.println(addAsterisks("fun"));
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program of wordSearch puzzle that use the following text file as an input. The...
Write a program of wordSearch puzzle that use the following text file as an input. The output should be like this: PIXEL found (left) at (0,9). ( Use JAVA Array ) .Please do not use arrylist and the likes! Hints • The puzzle can be represented as a right-sized two-dimensional array of characters (char). • A String can be converted into a right-sized array of characters via the String method toCharArray. . A word can occur in any of 8...
Read the following cases and decide the right supplement for each case. Highlight the supplement name...
Read the following cases and decide the right supplement for each case. Highlight the supplement name by finding the word from the given box. Follow the given example: Example: Naif has an infection. He needs an antibiotic Maryam cannot digest milk. She needs to have ___lactase______ supplements Majid is overweight. He decided to buy _________ supplements to help him lose weight. Muntaha’s nails always breaks so easily. She wants to get _________ supplements. Munther face looks older than his age....
pseudocode please!! Assignment6C: P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but...
pseudocode please!! Assignment6C: P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way called “leet” – short for “elite”. In essence, it was a simple character replacement algorithm, where a single “regular” character was replaced by one or more “leet” characters; numbers remained the same. Here’s one of the most readable versions: a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t 7 z Z c (...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
QUESTION 19 A key distribution and authentication method used by every operating system. It uses a...
QUESTION 19 A key distribution and authentication method used by every operating system. It uses a shared secret key and can also be used for single sign-on operations. 2 points    QUESTION 20 Authentication method that allows a user to authenticate once and use multiple services without having to re-authenticate. 2 points    QUESTION 21 Protocol that establishes the security association for the Authentication Header (AH) or the Encapsulating Security Payload (ESP) in IPsec, and provides keys for both AH...
define a function,character, with parameter values and word that takes in a dictionary of letter values...
define a function,character, with parameter values and word that takes in a dictionary of letter values and a string. Based on the values in the dictionary, return the "score" that corresponds with the word parameter. NOTE: Assume all words and letter values will be lowercase. examples: values = {'a': 5, 'b': 5, 'c': 5, 'd': 5, 'e': 5, 'f': 5, 'g': 5, 'h': 5, 'i': 5, 'j': 5, 'k': 5, 'l': 5, 'm': 5, 'n': 5, 'o': 5} character(value,"ade") will...
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
Consider permutations of the 26-character lowercase alphabet Σ={a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}. In how many of these permutations do a,b,c...
Consider permutations of the 26-character lowercase alphabet Σ={a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}. In how many of these permutations do a,b,c occur consecutively and in that order? In how many of these permutations does a appear before b and b appear before c?
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as an input. The first task is to compute the frequency of each character appearing in the string. In the output, the characters have to be arranged in the same order as they appear in the input string. Then characters have to be rearranged, such that all the characters having a specific frequency, say xx, come together. Let the frequency of a character, lying in...