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
If you have long column labels with columns so wide that they affect the readability of a worksheet you should first
jonny [76]
You should first .<span>consider how you could shorten the column labels.
Shortening the column labels could be easily done by dragging the column to the size that we want. But when shortening the column labels, some problems might occur such as the content might be distorted and in will become unevenly placed.</span>
5 0
3 years ago
Read 2 more answers
Input 3 positive integers from the terminal, determine if tlrey are valid sides of a triangle. If the sides do form a valid tria
butalik [34]

Answer:

In Python:

side1 = float(input("Side 1: "))

side2 = float(input("Side 2: "))

side3 = float(input("Side 3: "))

if side1>0 and side2>0 and side3>0:

   if side1+side2>=side3 and side2+side3>=side1 and side3+side1>=side2:

       if side1 == side2 == side3:

           print("Equilateral Triangle")

       elif side1 == side2 or side1 == side3 or side2 == side3:

           print("Isosceles Triangle")

       else:

           print("Scalene Triangle")

   else:

       print("Invalid Triangle")

else:

   print("Invalid Triangle")

Explanation:

The next three lines get the input of the sides of the triangle

<em>side1 = float(input("Side 1: ")) </em>

<em>side2 = float(input("Side 2: ")) </em>

<em>side3 = float(input("Side 3: ")) </em>

If all sides are positive

if side1>0 and side2>0 and side3>0:

Check if the sides are valid using the following condition

   if side1+side2>=side3 and side2+side3>=side1 and side3+side1>=side2:

Check if the triangle is equilateral

<em>        if side1 == side2 == side3: </em>

<em>            print("Equilateral Triangle") </em>

Check if the triangle is isosceles

<em>        elif side1 == side2 or side1 == side3 or side2 == side3: </em>

<em>            print("Isosceles Triangle") </em>

Otherwise, it is scalene

<em>        else: </em>

<em>            print("Scalene Triangle") </em>

Print invalid, if the sides do not make a valid triangle

<em>    else: </em>

<em>        print("Invalid Triangle") </em>

Print invalid, if the any of the sides are negative

<em>else: </em>

<em>    print("Invalid Triangle")</em>

4 0
3 years ago
Edward scissorhands Of course, Jim is the villain, but who or what is the antagonist in the film? Explain in detail.
Doss [256]
Jim is the main antagonist while Edward is the main protagonist of the movie.
8 0
2 years ago
What's the component of the hardware?​
melisa1 [442]
Some component of the hardware are central processing unit (CPU), monitor, mouse, keyboard, computer data storage, graphics card, sound card, speakers and motherboard.

I’m sure theirs more but here’s so. Hope this helps!
7 0
2 years ago
Read 2 more answers
The more employees can do, the less they have to be managed by supervisors.
zheka24 [161]
False
Don’t take me too seriously cause I could be wrong, but I think it’s false. Unless the employees are like the best hardworking employees, they will likely slack off the second they get the chance. The more they can do just means that they can do more, it doesn’t necessary mean they need less supervision
4 0
3 years ago
Read 2 more answers
Other questions:
  • A base class named Garden contains a private field width and a property public int Width that contains get and set accessors. A
    11·1 answer
  • Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if appropriate. Granite Sales C
    12·1 answer
  • When you write a C# program that stores a value in a variable, you are using temporary storage; the value you store is lost when
    12·1 answer
  • Your desktop, internet explorer, and the media player can be started from this area on most computers
    9·1 answer
  • When working on developing an ability, it is important to get feedback to know how you are doing.
    6·1 answer
  • What is a third variable condition that could create the following correlation?
    10·2 answers
  • Can someone help me write an algorithm and a flow chart pls for question 3
    7·1 answer
  • Which of the following describe audio-editing software? Choose all that apply.
    5·2 answers
  • Convertbinary(111100)to decimal​​​​
    13·2 answers
  • Explain information technology ?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!