Skip to content

Commit

Permalink
Create csc120 hw3
Browse files Browse the repository at this point in the history
  • Loading branch information
attorri authored Oct 3, 2021
0 parents commit e504b66
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions csc120 hw3
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);
}

}
}

0 comments on commit e504b66

Please sign in to comment.