From a given
string of numeric values, print the individual numbers in words separated by space.
Input: “2491"
i have written the below prog for the same.
public class notoword {
public static void main(String[] args) {
int n=2346980;
int d;int rev=0;
while(n!=0){
d=n%10;
rev=rev*10+d;
n=n/10;
}
int num=rev;
while(num!=0){
d=num%10;
switch(d){
case 1:System.out.println("one");
break;
case 2:System.out.println("two");
break;
case 3:System.out.println("three");
break;
case 4:System.out.println("four");
break;
case 5:System.out.println("five");
break;
case 6:System.out.println("six");
break;
case 7:System.out.println("seven");
break;
case 8:System.out.println("eight");
break;
case 9:System.out.println("nine");
break;
}
num=num/10;
}
}
}
its not giving output for any string like 2340,9070.
I know I am dividing it by 10 so there is no output for this kind of input.
Please correct my programme as required.And can any one suggest any better solution for this.
Thanks in advance.