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
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
Post a Comment