write a program in bluej to input natural numbers between 1 to 1000 and then output it in words. for ex-
input:29
output:two Nine
Answers
class Ans
{
public static void main(String[] args)
{
int a = 1234;
int number;
String s="";
while(a>0)
{
number = a%10;
//removing one digit after
//every iteration
a=a/10;
if(number==0)
s="zero "+s;
else if(number==1)
s="one "+s;
else if(number==2)
s="two "+s;
else if(number==3)
s="three "+s;
else if(number==4)
s="four "+s;
else if(number==5)
s="five "+s;
else if(number==6)
s="six "+s;
else if(number==7)
s="seven "+s;
else if(number==8)
s="eight "+s;
else if(number==9)
s="nine "+s;
}
System.out.println(s); }
}