1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Zepler [3.9K]
3 years ago
8

Write a recursive function named lettersOnly that accepts a string s as a parameter and returns a string with the same character

s as s, in the same order, but excluding any characters that are not alphabetic letters from A-Z, case-insensitive. For example, the call of lettersOnly("{[[Friends, save $$$ with 'Geico'!!]]}") should return "FriendssavewithGeico". If the string passed is empty or contains no letters, return an empty string.
Computers and Technology
1 answer:
dem82 [27]3 years ago
3 0

Answer:

/*

 * Method to print the letters in a passed in string by recursion. Each

 * recursion compresses the string by excluding the last character one at a time

 */

public static void lettersOnly(String s) {

 //If string is empty, return nothing

 if (s.length() < 1) {

  return;

 }

 

 // Get the last character of the string

 char x = s.charAt(s.length() - 1);

 // Check if the length of the string is 1 or less

 // If it is 1 or less, check if the character is an alphabet

 // A character x is an alphabet if its ASCII representation is

 // between 65 and 90 (both inclusive) for uppercase letters

 // or between 97 and 122 (both inclusive) for lowercase letters

 // To get the ASCII representation, the character is type cast by prepending it

 // with (int) e.g (int) z gives 122

 if ((s == null) || (s.length() <= 1)) {

  if ((((int) x >= 65 && (int) x <= 90)) || ((int) x >= 97 && (int) x <= 122))

   System.out.println(s);

 }

 // else, if the length of the string is more than 1

 else {

  // Get the substring including all the characters in the string except the last

  // character.

  // Recall the function lettersOnly on the substring

  lettersOnly(s.substring(0, s.length() - 1));

  // Check if the last character of the string is an alphabet

  // If it is, print it out.

  if ((((int) x >= 65 && (int) x <= 90)) || ((int) x >= 97 && (int) x <= 122))

   System.out.print(s.charAt(s.length() - 1));

 }

} // End of method

Explanation:

Read through the comments of the code for better readability and understanding. To get a better representation of the code, the source file code has been attached to this response. Please download it and you can run it as a Java application on your machine.

Hope this helps!

Download java
You might be interested in
If you wish to include a header or footer on all pages in a publication, you will need to insert this by navigating to the _____
Marina86 [1]
If you wish to include a header or footer on all pages in a publication, you will need to insert this by navigation to the master page.
7 0
4 years ago
Read 2 more answers
The ________ is the biggest power consumer on a mobile computing device. display CPU memory module hard drive
user100 [1]

Answer:

CPU (Central Processing Unit)

6 0
3 years ago
How many 32 bit integers can be stored in 16 byte cache block in matlab?
Sladkaya [172]
Bytes have eight bits. 32 bits would be four bytes.
4 0
4 years ago
Jack, a skillful hacker targeted a major banking services firm located in Japan, using the LOIC (Low Orbit Ion Cannon) tool, Jac
Elenna [48]

Answer:

denial-of-service attack (DoS attack) and distributed denial-of-service attack (DDoS attack)

Explanation:

Denial-of-service attack -

It is a type of cyber attack , where the hacker can create a machine or any network resource , which is capable to disrupt the server of the host , with the help of the internet , is referred to as the denial of service attack .

The task is accomplished with by flooding the host with many superfluous requests , which can overload the system .

In case of the distributed denial-of-service attack , the flooding is done by many different sources .

Hence , from the given scenario of the question ,

The correct answer is  denial-of-service attack (DoS attack) and distributed denial-of-service attack (DDoS attack) .

4 0
4 years ago
If you accidentally put an envelope in the Express Mail box will it still get to its destination?
Gnoma [55]
It depends because if you put a stamp on the envelope. But I think that it will still get to the destination. I think that it will either get sent to the destination or not. But you never know what is going to happen.
8 0
3 years ago
Other questions:
  • Typically, a CLEP exam is taken by students who
    8·1 answer
  • The function below takes a single parameter number_list which is a list that can contain integers and floats. Complete the funct
    9·1 answer
  • How might writing an online journal be different than writing in a paper one ​
    15·2 answers
  • On Brainly, how can I change my username? from halfsidepancake​
    6·2 answers
  • Implement a java program to find the smallest distance between two neighbouring numbers in an array.
    7·1 answer
  • What means the data is still saved even if you turn the computer off or unplug it?​
    5·1 answer
  • Your program will be used by many departments at the university. Your comments will be important to their IT people. What would
    15·1 answer
  • A. Get a value for x from the user.
    13·1 answer
  • write a function that given an integer n returns the smallest integer greater than n the sume of whose digits is twice as big th
    13·1 answer
  • PLEASE HELP!
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!