Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class methodGradeLab {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- System.out.println("Input: ");
- String str = kb.nextLine();
- String Encoded = "";
- char ch=0;
- int count = 0;
- for (int x = 0; x < str.length(); x++) {
- if (ch == str.charAt(x)){
- count++;
- }
- else {
- Encoded = Encoded + ch;
- if(count != 0){
- Encoded = Encoded + count;
- }
- ch = str.charAt(x);
- count = 1;
- }
- }
- Encoded = Encoded + ch;
- if(count != 1){
- Encoded = Encoded + count;
- }
- System.out.println("Encoded: " + Encoded);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement