Java Program to display Numbers in Words | IT2305 - Java Programming Lab


AIM:
 To write a Java program to display the numbers in words (Conversion of Numbers to Words) in IT2305 - Java Programming Laboratory.

SOURCE CODE:
import java.util.*;
class Display
{
 public static void main(String args[])
 {
  int n,s=0,a,p,i=1,count=0,n1;
  Scanner sin=new Scanner(System.in);
   n=sin.nextInt();
   while(n>0)
   {
    n1=n%10;
    s=s*10+n1;
    n=n/10;
    count++;
    }
  while(s>0)
  {

   p=s%10;
   s=s/10;
 switch(p)
 {
case 1:
  System.out.println("one");
  break;
case 2:
  System.out.println("two");
  break;
case 3:
  System.out.println("three");
  break;
case 4:
  System.out.println("four");
  break;
case 5:
  System.out.println("five");
  break;
case 6:
  System.out.println("six");
  break;
case 7:
  System.out.println("seven");
  break;
case 8:
  System.out.println("eight");
  break;
case 9:
  System.out.println("nine");
  break;
case 0:
  System.out.println("zero");
  break;
  }  i++;
}
while(i<=count)
System.out.println("zero");
i++;
}
}
Previous
Next Post »

Still not found what you are looking for? Try again here.