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
pishuonlain [190]
3 years ago
12

How would I do this code with a while loop to remove the letters? Please and thank you

Computers and Technology
1 answer:
dusya [7]3 years ago
7 0

There is of course a replace() function in java that lets you do this without a while loop. If you want to do it letter by letter, it gets a little complicated because you have to take care not to index the string outside its bounds.

I did not bother to create a separate runner class. The Main is just inside this class and everything is static.

public class LetterRemover {

   public static String RemoveLetters(String s, char c)

   {

       int loc = s.indexOf(c);

       while(loc >= 0)

       {            

           if (loc == 0) {

               s = s.substring(1);

           } else if (loc == s.length()-1) {

               s = s.substring(0, loc);

           } else {

               s = s.substring(0, loc) + s.substring(loc+1);

           }

           loc = s.indexOf(c);

       }

       return s;

   }

   public static void Test(String s, char c) {

       System.out.format("%s - letter to remove %c\n%s\n", s, c, RemoveLetters(s,c));

   }

   

   public static void main(String[] args) {

       Test("I am Sam I am", 'a');

       Test("ssssssssxssssesssssesss", 's');

       Test("qwertyqwertyqwerty", 'a');

   }

}

You might be interested in
A major retailer wants to enhance their customer experience and reduce losses
VikaD [51]

Answer:

Predict Demand

Explanation:

The type of Artificial Intelligence (Al) solution that would be suitable for solving this problem is "Predict Deman"

By predicting the demand of the potential consumer through the Artificial intelligence solution the retailer would be able to eliminate leftover out-of-stock scenarios because the adequate quantity of the products or demands will be provided thereby enhancing customers' experience arising from out-of-stock scenarios and reducing losses arising from the leftover.

8 0
3 years ago
Most editing commands in Word, such as cut, copy, and paste, can be found on which tab?
Anettt [7]
All these commands can be found on the home tab. Keyboard shortcuts (Ctrl-X, Ctrl-C, Ctrl-V) are also editing shortcuts.

:)
7 0
3 years ago
Read 2 more answers
Which statement correctly differentiates how to use list and table styles?
irina [24]
What statement please explain correctly
5 0
3 years ago
Read 2 more answers
which programming paradigm do programmers follow to write code for event driven applications? a. object oriented programming. b.
7nadin3 [17]

Answer:

D) Procedural

Explanation:

7 0
3 years ago
Brenda's meeting with the web developer of her retail website concerning the integration of conversion tracking using Google Ads
RideAnS [48]

The web developer needs to have Brenda's Auto-tagging turned on in all of her Google Ads.

Explanation:

Auto-tagging features when turned on are able to track conversions on your website. Auto–tagging when combined with conversion tracking using Google Ads helps you see how effective your ad clicks are from potential customers. If Brenda’s auto-tagging is enabled, a Google Click Identifier will be registered and stored in what developers call Google Analytics. Brenda will then be able to go to Google Analytics and see customer clicks for website’s purchases, downloads, and more. By default, auto-tagging is turned. To turn it on, the web developer needs to

Sign into Brenda's Google ad account

Click settings in the left pane and select account settings

The web developer would then be able to enable auto-tagging and save the settings.

Learn more about Google Analytics and its connection to conversion tracking

brainly.com/question/13234037

brainly.com/question/14280673

#LearnWithBrainly

4 0
4 years ago
Other questions:
  • What is meant by Angular 4?
    15·2 answers
  • Where is the cell membrane located in cell that do not have cell wall
    7·2 answers
  • Which service is used when your email program exchanges messages with the mail server on a distant network?
    5·1 answer
  • An intranet that is partially accessible to authorized people outside the business or organization is known as an
    7·2 answers
  • People who score high on the Big Five trait dimension of ________ tend to use more adjectives in their e-mail communications. Gr
    15·1 answer
  • Emanuel studies hard for hours on end until bedtime, yet his grades could be better. What can he do to improve his academic perf
    6·1 answer
  • To qualify for a particular scholarship, a student must have an overall grade point average of 3.0 or above and must have a scie
    8·2 answers
  • Which of these is true about moores law
    6·1 answer
  • SOMEONE HELP ME PLEASE <br> What are three reasons technology is beneficial to teens
    11·1 answer
  • As a hardware technician and knowing the internet components of the system unit, list any five(5) of such components.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!