In: Computer Science
Write a program which compresses a given string of 1s and 0s and uncompress the string that was compressed. Use the run-length compression technique which replaces runs of 0s with a count of how many 0s.
The interactive input/output should allow users to select and run required processes.
The assignment submission on Blackboard should be as CIS_232_Project_LastName.zip file and include:
project report file: ProjectReportLastName.doc
program’s source file: ProjectLastName.java
program’s bytecode file: ProjectLastName.class
and any other relevant files.
The project report should be prepared by using word processing software. To write a program you should complete and include in your assignment report the following steps:
Title:
Student’s name:
CIS 232 Introduction to Programming
Programming Project
Due Date: November 30, 2020
Instructor Dr. Lomako:
The following program asks the user to enter a string of 0's and 1's. It then computes the running length of 0's and 1's. And then finally displays the character and its running length as the encoded form of the message.
For example, if the string is 00011111, then the encoded message will be 0315, that means the character 0 has a running length of 3 and the character 1 has a running length of 5.
Program:
import java.util.*;
public class ProjectLastName
{
public static void main(String[] args)
{
Scanner sc= new
Scanner(System.in);
System.out.print("Enter the string:
");
String str=sc.nextLine();
int l=str.length();
int count;
System.out.print("Encoded string
is: ");
for(int i=0;i<l;i++)
{
count=1;
while
(i<l-1&&str.charAt(i)==str.charAt(i+1))
{
count++;
i++;
}
System.out.print(str.charAt(i));
System.out.print(count);
}
}
}
Program Screenshot:
Output Screenshot:
1.
2.