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 computer is the __________ of an attack when it is used to conduct an attack against another computer.
MariettaO [177]

Answer:

A computer is the __________ of an attack when it is used to conduct an attack against another computer.

Answer: Subject

Explanation:

4 0
2 years ago
Which tab is used to edit objects on the slide master and layouts
Paul [167]
When you want all your slides to contain the same fonts and images (such as logos), you can make those changes in one place—the Slide Master, and they'll be applied to all your slides. To open Slide Master view, on the View tab, select Slide Master:
7 0
3 years ago
The _____ is the area in Microsoft Excel where you can perform file commands such as Save, Open, and Print
Xelga [282]
I believe the answer is Backstage view
Back stage view gave you the complete command as options for users to manage our files and data in the office such as saving, print, inspecting meta data, etc. To access backstage view, you just need to click the file tab on left top corner.
5 0
3 years ago
Read 2 more answers
Ted is asked to create a page of family photos for his family reunion Web site. He will have about 20 pictures to post, with a c
Alja [10]

Answer:

A

Explanation:

© is the symbol for copyright or Copr. for abbreviation.

7 0
4 years ago
A router has just received the following new IP addresses: 88.62.108.0/21, 88.62.116.0/21, 88.62.120.0/21 and 88.62.128.0/21. If
Natali [406]

Answer:

Yes, they can be aggregated into a single network address of 88.62.0.0/16

Explanation:

Since they all will be using the same outgoing interface so they can be grouped according to next hop which appears to be the same for all four IP address.

First convert all the network addresses into binary.

DECIMAL                      BINARY                                                      CLASS OF IP

88.62.108.0/21            01011000.00111110.01101100.00000000      Class A

88.62.116.0/21             01011000.00111110.01110100.00000000     Class A

88.62.120.0/21            01011000.00111110.01111000.00000000     Class A

88.62.128.0/21           01011000.00111110.10000000.00000000    class A

Looking at the binary form of the address from left to right it can be observed that all for address are identical in the first two octet, that is up to the 16th digit.

So the new subnet mask will be /16, using any of the four address and the /16 mask will can obtain the new network address

All four address can be summarized as 88.62.0.0/16

4 0
3 years ago
Other questions:
  • When might it be necessary or advisable to write a shell script instead of a shell function? give as many reasons as you can thi
    15·1 answer
  • In your memo, give three new employees directions for starting the computer and opening a word-processing document.
    9·1 answer
  • Which is an advantage of setting bookmarks?
    15·1 answer
  • A _____ is made up of rows and columns and is used to organize information.
    12·2 answers
  • Why does my inbox keep getting notifications and then disappearing?
    15·2 answers
  • Please can someone help me with this?
    6·1 answer
  • A sum of money is shared between 2 friends in the ratio 2 : 3. If the larger
    9·1 answer
  • Assume that you have implemented a sequence class. Describe the mySequence object (i.e., items with the correct order and the po
    9·1 answer
  • Identify the programmer’s responsibility in maximizing the programs reliability by having awareness of the beneficial and harmfu
    8·1 answer
  • What are the 3 attributes of information?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!