Quote Originally Posted by [email protected] View Post
Hey guys here is the solution:


package com.test.jguru;

import java.util.Hashtable;
import java.util.Map;

public class ChallengeNumber {

/**
* @param args
*/
public static void main(String[] args) {
Map<Integer,String> mapNum = new Hashtable<Integer, String>();
mapNum.put(1, "one");
mapNum.put(2, "two");
mapNum.put(3, "three");
mapNum.put(4, "four");
mapNum.put(5, "five");
mapNum.put(6, "six");
mapNum.put(7, "seven");
mapNum.put(8, "eight");
mapNum.put(9, "nine");

String strNum = "10444221";
System.out.println("String Length "+strNum.length());
int count = 0;
for(int i = 0;i<strNum.length();i++){
if(!(i+1 == strNum.length())){
if(strNum.charAt(i) == strNum.charAt(i+1)){
count++;
}else{
System.out.println(mapNum.get(count+1)+" "+strNum.charAt(i)+(mapNum.get(count+1)!="one"? "s":""));
count = 0;
}
} else{
System.out.println(mapNum.get(count+1)+" "+strNum.charAt(i)+(mapNum.get(count+1)!="one"? "s":""));
}
}

}

}
This code will work for all the combinations