-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e504b66
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import java.util.*; | ||
import javax.swing.JOptionPane; | ||
import java.lang.*; | ||
import java.io.*; | ||
import java.util.Random; | ||
public class Main | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
System.out.println("Hello World"); | ||
Scanner keyboard = new Scanner(System.in); | ||
System.out.println("today we are going to implement Run Length Encoding (RLE)"); | ||
System.out.println("here is an example of RLE"); | ||
String example="wwwcccsssccccom"; | ||
int n = example.length(); | ||
for (int i=0; i<n; i++) | ||
{ | ||
int count =1; | ||
int n_minus_1 = n-1; | ||
while (i<n_minus_1 && example.charAt(i) == example.charAt(i+1)) | ||
{ | ||
count++; | ||
i++; | ||
} | ||
System.out.print(example.charAt(i)); | ||
System.out.print(count); | ||
} | ||
System.out.println("\nthis was of the example string, "+example); | ||
System.out.println("now, let's have you enter a string"); | ||
String input_RLE; | ||
input_RLE = keyboard.nextLine(); | ||
int z = input_RLE.length(); | ||
for (int k=0; k<z; k++) | ||
{ | ||
int counter =1; | ||
int z_minus_1 = z-1; | ||
while (k<z_minus_1 && input_RLE.charAt(k) == input_RLE.charAt(k+1)) | ||
{ | ||
counter++; | ||
k++; | ||
} | ||
System.out.print(input_RLE.charAt(k)); | ||
System.out.print(counter); | ||
} | ||
|
||
} | ||
} |