CODE IN JAVA:
StringDemo.java file:
import java.util.Scanner ;
public class StringDemo {
public static int charCount(String s, char c) {
if(s.length() == 0)
return 0;
if(s.length() == 1) {
if(s.charAt(0)
== c)
return 1;
return 0;
}
if(s.charAt(0) == c)
return 1 +
charCount(s.substring(1), c);
return charCount(s.substring(1),
c);
}
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.print("Enter a string :
");
String s = sc.nextLine();
System.out.print("Enter a character
: ");
char ch =
sc.next().charAt(0);
System.out.printf("The number of
occurences of %c in the string %s = %d", ch, s,
charCount(s,ch));
}
}
OUTPUT:
java 2. Write a recursive method to return the number of occurrences a character c in...
Java Program Write a recursive method that takes a string and return a string where every character appears twice. Output must match exactly as below: only two LL's since there is already two of the character For example, if the string is “HELLO”, it will return “HHEELLOO”. Write a program to test it. must be recursive!!!
Write a recursive method that counts the number of vowels in a string. It must return the number of vowels. Use appropriate parameters as needed. Hint: There's an ArrayList method called contains that might make checking whether a character is a vowel easier.
Write a recursive function that uses the strchr() function to display the number of occurrences of a character inside a string. Create a C program to read a string of less than 10 characters and a character and calls the function.
MUST BE IN JAVA AND USE RECURSION Write a recursive method that returns the number of all occurrences of a given word in all the files under a directory. Write a test program. Use the following header: public static long findInFile(File file, String word)
//Write a recursive function that, given an input string str, replaces all occurrences of a character a by a character b in str. (C++) void replace_chr(char *str, char a, char b){ }
Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified character in a string) Write a recursive function that finds the number of occurrences of a specified letter in a string using the following function header. int count(const string& s, char a) For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string and a character, and displays the number of occurrences for the character in the...
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...
JAVA Help Write an application that inputs a line of text and a search character and uses String method indexOf to determine the number of occurrences of the character in the text.
Write a Java method that searches a 2-d array for a specific character. Return the index of the first location of the character. Method header: public static void play(char c, char[][]wordSearch){ Example: a e v s l g r e d k h k q s e z j c p o a t s o v a n m n l q p f o x b The character 's' appears at index 0,3.
write a recursive method to determine if the entire string is uppercase character