Write a Program input four number convert into like this 9999=nine thousand nine hundred ninety nine
If input 9991=nine thousand nine hundred ninety one
import java.io.*;
class program
{
public static void main(String args[])
{
int a,b,c,d,e;
Console con = System.console();
a = Integer.parseInt(con.readLine());
b = a%10;
a = a/10;
c = a%10;
a = a/10;
d = a%10;
a = a/10;
e = a%10;
switch(e)
{
case 1: System.out.print("One thousand"); break;
case 2: System.out.print("Two thousand"); break;
case 3: System.out.print("Three thousand"); break;
case 4: System.out.print("Four thousand"); break;
case 5: System.out.print("Five thousand"); break;
case 6: System.out.print("Six thousand"); break;
case 7: System.out.print("Seven thousand"); break;
case 8: System.out.print("Eight thousand"); break;
case 9: System.out.print("Nine thousand"); break;
}
switch(d)
{
case 1: System.out.print(" One hundred"); break;
case 2: System.out.print(" Two hundred"); break;
case 3: System.out.print(" Three hundred"); break;
case 4: System.out.print(" Four hundred"); break;
case 5: System.out.print(" Five hundred"); break;
case 6: System.out.print(" Six hundred"); break;
case 7: System.out.print(" Seven hundred"); break;
case 8: System.out.print(" Eight hundred"); break;
case 9: System.out.print(" Nine hundred"); break;
}
if(c==1)
{
switch(b)
{
case 0: System.out.print(" ten"); break;
case 1: System.out.print(" eleven"); break;
case 2: System.out.print(" twelve"); break;
case 3: System.out.print(" Thirteen"); break;
case 4: System.out.print(" Fourteen"); break;
case 5: System.out.print(" Fifteen"); break;
case 6: System.out.print(" Sixteen"); break;
case 7: System.out.print(" Seventeen"); break;
case 8: System.out.print(" Eighteen"); break;
case 9: System.out.print(" Nineteen"); break;
}
}
switch(c)
{
case 2: System.out.print(" Twenty"); break;
case 3: System.out.print(" Thirty"); break;
case 4: System.out.print(" Forty"); break;
case 5: System.out.print(" Fifty"); break;
case 6: System.out.print(" Sixty"); break;
case 7: System.out.print(" Seventy"); break;
case 8: System.out.print(" Eighty"); break;
case 9: System.out.print(" Ninety"); break;
}
switch(b)
{
case 1: System.out.print(" One"); break;
case 2: System.out.print(" Two"); break;
case 3: System.out.print(" Three"); break;
case 4: System.out.print(" Four"); break;
case 5: System.out.print(" Five"); break;
case 6: System.out.print(" Six"); break;
case 7: System.out.print(" Seven"); break;
case 8: System.out.print(" Eight"); break;
case 9: System.out.print(" Nine"); break;
}
}
}
Comments
Post a Comment