Recursive program to extract digits and print them in words.

Recursive program to extract digits and print them in words.

class digword //start of class
{
public void accept ( int num )
{

System.out.println(" The number is "+ "\t\t"+ num);
int p= revdig( num);
}
public int revdig ( int k)
{

String a[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
if (k==0){

return 0;
}
else
{
int r=k%10;
System.out.println("the number"+"\t\t"+r+"\t\t"+ "in words"+"\t" +a[r]);
}
return revdig(k/10);
}// end of method
}// end of class
OUTPUT---
The number is 2442441
the number 1 in words one
the number 4 in words four
the number 4 in words four
the number 2 in words two
the number 4 in words four
the number 4 in words four
the number 2 in words two

Comments

Popular posts from this blog

Sort Boundary Elements Of A Matrix

Lucky Number In Java ISC

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.