48) Write a program to input a number and print all Digit in Words of a number?(123==one two three)
import java.util.*;
public class Digit_in_words_7
{
public static void main(String args[ ])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number");
int a = sc.nextInt();
int k = a;
int p = a;
String s = "";
int c = 0;
while(p>0)
{
p=p/10;
c++;
}
int x = (int)Math.pow(10,(c-1));
System.out.print(a+" = ");
while(k>0)
{
int d = k/x;
k=k%x;
x=x/10;
if(d==1)
{
s = "One";
}
else if(d==2)
{
s = "Two";
}
else if(d==3)
{
s = "Three";
}
else if(d==4)
{
s = "Four";
}
else if(d==5)
{
s = "Five";
}
else if(d==6)
{
s = "Six";
}
else if(d==7)
{
s = "Seven";
}
else if(d==8)
{
s = "Eight";
}
else if(d==9)
{
s = "Nine";
}
System.out.print(s+" ");
}
}}
Output :
digit-in-words |