NUMERALS TO WORD
JAVA PROGRAM TO CONVERT NUMERALS TO WORDS:
Example:
12.02:- TWELVE Rupees 2 PAISE.
CODING:
import java.io.*;
class prog
{
String convert(long n)
{ String wrd[]={"","ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINETY"};
if(n<21)
return(wrd[(int)n]+" ");
else
{long d1=n/10,d2=n%10;return(wrd[(int)(18+d1)]+" "+wrd[(int)d2]+" ");
}
}
public static void main(String args[])throws IOException
{prog ob=new prog();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\t INPUT\t\t:\n Enter the number : ");
String s=br.readLine();
long a=Long.parseLong(s.substring(0,(s.indexOf('.'))));
String b1=s.substring(s.indexOf('.')+1);
if(b1.length()<2)
b1=b1+"0"+"0";
long b=Long.parseLong(b1.substring(0,2));
String w[]={"CRORE","LAKH","THOUSAND","HUNDRED"};
long no[]={10000000,100000,1000,100};String p="";
for(int i=0;i<4;i++)
{if(a/no[i]>0)
p=p+" "+ob.convert(a/no[i])+w[i];a=a%no[i];
}
p=p+" "+ob.convert(a)+" Rupees";
if(b>0)
p=p+" "+ob.convert(b)+" Paise";
System.out.println(p);
}
}
Comments
Post a Comment