-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsc120 hw3
47 lines (46 loc) · 1.21 KB
/
csc120 hw3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
}
}
}