Java compressing Strings

前端 未结 20 1059
误落风尘
误落风尘 2020-11-29 09:24

I need to create a method that receives a String and also returns a String.

Ex input: AAABBBBCC

Ex output: 3A4B2C

Well, this is quite embarrassing a

20条回答
  •  半阙折子戏
    2020-11-29 10:06

    The code below will ask the user for user to input a specific character to count the occurrence .

    import java.util.Scanner;
    
    class CountingOccurences {
    
    public static void main(String[] args) {
    
        Scanner inp = new Scanner(System.in);
    
        String str;
        char ch;
        int count=0;
    
        System.out.println("Enter the string:");
        str=inp.nextLine();
        System.out.println("Enter th Char to see the occurence\n");
        ch=inp.next().charAt(0);
    
        for(int i=0;i

提交回复
热议问题