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
cricket20 [7]
4 years ago
7

Write a method called compress that takes a string as input, compresses it using rle, and returns the compressed string. case ma

tters - uppercase and lowercase characters should be considered distinct. you may assume that there are no digit characters in the input string. there are no other restrictions on the input - it may contain spaces or punctuation. there is no need to treat non-letter characters any differently from letters.
Computers and Technology
1 answer:
MaRussiya [10]4 years ago
5 0
<span>public static String compress (String original) { StringBuilder compressed = new StringBuilder(); char letter = 0; int count = 1; for (int i = 0; i < original.length(); i++) { if (letter == original.charAt(i)) { count = count + 1; } else { compressed = count !=1 ? compressed.append(count) : compressed; compressed.append(letter); letter = original.charAt(i); count = 1; } } compressed = count !=1 ? compressed.append(count) : compressed; compressed.append(letter); return compressed.toString(); }</span>
You might be interested in
Insecurely attached infants who are left my their mothers in an unfamiliar setting often will
Temka [501]

Insecurely attached infants who are left my their mothers in an unfamiliar setting often will Hold fast in their mothers in their return.

A. Hold fast in their mothers in their return

<u>Explanation:</u>

It is in the conscience of the infants to have the company of their parents no matter the place or time and do not generally like to be left alone. Moreover, the questions says, insecurely attached infants which further add up to this behavior.

The infant would not explore the surroundings due to lack of confidence in an unfamiliar setting. They would rather be uncomfortable and most probably weep the time until their mother arrives and hold fast on to them on their return.  

8 0
4 years ago
Lisa is modifying a spreadsheet. Which view enables her to see how her changes will look when she prints the spreadsheet?
emmainna [20.7K]
The page layout view

The page layout view is useful for printing spreadsheets. It lets you review what you print and enables you to get a nice feel of the page when it is printed. All of the functions of the standard view are enabled and a few extra tools like ruler and header and footer fields that help achieve an awesome finish to your page.

 



5 0
4 years ago
Read 2 more answers
The registers are the communication channels inside the computer.( true or false)<br>​
ElenaW [278]
False
Registers are storage, not channels
6 0
3 years ago
How many bits are in a gigabyte in exponential form? ...?
notka56 [123]
1 gigabyte =
8000000000 bits

And exponential form is 8x10^9
8 0
4 years ago
Read 2 more answers
if you're using the paintbrush tool and want to change the color of the paint being used what should you change
Dmitry [639]

go to the color section and change the paint color

4 0
3 years ago
Read 2 more answers
Other questions:
  • A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that
    9·1 answer
  • Digital art is created by using
    6·1 answer
  • What is a collection of data that is stored in a computer system
    7·2 answers
  • Complete the following method named replaceEvens that receives the parameter numbers which is an array of integers. The method m
    5·1 answer
  • What happens when two computers use the same IP address?
    6·1 answer
  • "When an interrupt or a system call transfers control to the operating system, a kernel stack area separate from the stack of th
    11·1 answer
  • List the six external parts of a computer system and identify which are output and which are input devices.
    13·1 answer
  • It is also called teleconferencing or web conferencing,which is an online meeting wherein two or more people can see,hear,and ta
    14·1 answer
  • HELP ASAP. Which of the following is the best example of an installation issue? A computer can’t find the file that it needs to
    7·1 answer
  • In the code below, what's the final value of the variable x?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!