-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompressor
More file actions
43 lines (30 loc) · 1.15 KB
/
Compressor
File metadata and controls
43 lines (30 loc) · 1.15 KB
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
package javaapplication1;
import java.util.ArrayList;
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("What letters would you like to compress?");
String letters = input.next();
int counter = 0;
//System.out.println(letters.charAt(0));
letters += "1";
int size = letters.length();
ArrayList <String> list = new ArrayList<>();
for (int i = 0; i < size-1; i++) {
if ((letters.charAt(i)) == (letters.charAt(i+1))) {
//System.out.println(letters.charAt(i));
counter++;
//list.add(String.valueOf(letters.charAt(i)));
}
else{
list.add(String.valueOf(letters.charAt(i)) + String.valueOf(counter + 1));
counter = 0;
}
}
System.out.println("~~~~~~~~~~~~~~~~~");
for(int i = 0; i < list.size();i++){
System.out.print(list.get(i));
}
}
}