Finoit Interview Question

Programming questions. there are two programming questions which should be done on machine,and both should be correct. 1. Compress the string. aaaaabbbbbbbcccc=a5b6c4. 2. don't know the question but it's on recurssion.

Interview Answer

Anonymous

May 18, 2018

public class MyClass { public static void main(String args[]) { String s1="aaaaabbbbbbcccc"; int len=s1.length(); int l=0,m=0,n=0; for(int i=0;i<=len-1;i++){ if(s1.charAt(i)=='a') { l++; } else if(s1.charAt(i)=='b') { m++; } else n++; } System.out.print("a"+l+"b"+m+"c"+n); } }