import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
for(int i=0;i<s.length()-1;){
int count = 0;
for(int j = i+1;j<s.length();j++){
System.out.println(s.charAt(i));
System.out.println(s.charAt(j));
if(s.charAt(i) == s.charAt(j))
count++;
}
System.out.print(s.charAt(i));
System.out.println(count);
if(count>1)
System.out.print(count);
i = i+count;
}
}
}
String string compression(my run code option is not working for this program can u help me out ))
your logic is not correct and moreover we dont require 2 loops to solve this ques…
here is an easy way of approaching this ques
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
int count = 1;
for(int i=0;i<s.length()-1;i++){
if(s.charAt(i)==s.charAt(i+1)){
//do something(on count)
}else{
//do something(print the ith character, count(if it is greater than 1) and set count to 1 again)
}
}
// print the last character and count(if it is greater than 1)
}
}