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
mariarad [96]
3 years ago
5

Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its left and

right are gone. So "ab*cd" yields "ad" and "ab**cd" also yields "ad".
starOut("ab*cd") → "ad"

starOut("ab**cd") → "ad"

starOut("sm*eilly") → "silly


Provided statement:


public String starOut(String str) {


//code goes here


}
Computers and Technology
1 answer:
wariber [46]3 years ago
3 0

Answer:

// class definition Solution

public class Solution {

   // main method to begin program execution

   public static void main(String args[]) {

       // the starOut method is called with argument

       starOut("ab*cd");

       starOut("ab*cd");

       starOut("sm*eilly");

   }

   

   // the starOut method is declared and it returns a string

   // it receive a string as the argument

   public static String starOut(String str) {

       // The index of the star is assigned to starIndex

       int starIndex = str.indexOf("*");

       // Index of character before star is known

       int charBeforeStar = starIndex - 1;

       // Index of character after star is known

       int charAfterStar = starIndex + 1;

       // The newString is declared empty

       String newString = "";

       // loop through the string

       for (int i =0; i < str.length(); i++){

           // if i is either of the following index, the loop continue

          // without concatenating with the newString

           if (i == charBeforeStar || i == charAfterStar || i == starIndex){

               continue;

           }

           // the new string is concatenated with a character

           newString += str.charAt(i);

       }

       

   // the new string is printed

       System.out.println(newString);

       // the newString is returned

       return newString;

   }

}

Explanation:

The code logic is stated in the comment inside the code.

You might be interested in
Which is the best response to receiving a threating text from a classmate
Yuri [45]

Answer:

send a threatening text in reply, then block the phone number block the phone number, then contact his phone service provider immediately delete the text, then report the incident to authorities ignore the message, then get a new cell phone number.

Explanation:

5 0
3 years ago
Read 2 more answers
Questions about the data policy and privacy policy of YT
Ilya [14]

Answer:

I'm confused

Explanation:

7 0
3 years ago
How to keep tools and equipment safeuh​
ivanzaharov [21]

Answer:

Use pelican, or similar heavy duty cases

Explanation:

Pelican is a brand btw. 10/10 would recommend

8 0
3 years ago
Read 2 more answers
Am i in elementary yes no
IgorLugansk [536]

Answer:

no

Explanation:

7 0
3 years ago
Which line of code will use the overloaded multiplication operation?
maks197457 [2]

Answer:

def __mul__(self, b):

Explanation:

correct edge 2021

4 0
2 years ago
Other questions:
  • What is the car on the right?
    7·1 answer
  • Within the sites that support disaster recovery, ___________ is a separate and fully equipped facility where the company can mov
    6·1 answer
  • What keyboard functions lets you delete words
    9·2 answers
  • Kyra is teaching a photography class. She would like her students to share photos. She would also like the students to be able t
    6·1 answer
  • PLS HURRRYYYYYY!1!1!1!1!1
    5·2 answers
  • Would you consider upgrading Maxine’s wardrobe a need or a want?
    11·1 answer
  • Are all the computer users known as programmer ​
    11·1 answer
  • What is Digital Citizen? It's one of my classes.
    5·1 answer
  • Write a Python program that uses three variables. The variables in your program
    12·1 answer
  • In what medium do web applications operate?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!