Convert integer to word using java Program

Convert integer to word using java

import java.util.Scanner;

class numtoletter

{

public static void main(String args[])

{

Scanner s=new Scanner(System.in);

System.out.print("Enter how many digits you want to store :");

int n=s.nextInt();

String a[]=new String[n];

System.out.print("nEnter number :");

int num=s.nextInt();

int i=0;

do

{

int r=num%10;

num=num/10;

switch(r)

{

case 0:a[i]="ZERO";break;

case 1:a[i]="ONE";break;

case 2:a[i]="TWO";break;

case 3:a[i]="THREE";break;

case 4:a[i]="FOUR";break;

case 5:a[i]="FIVE";break;

case 6:a[i]="SIX";break;

case 7:a[i]="SEVEN";break;

case 8:a[i]="EIGHT";break;

case 9:a[i]="NINE";break;

}

i++;

}while(num!=0);

System.out.println("nGiven number is");

for(int j=a.length-1;j>=0;j- -)

System.out.print(a[j]+"t");

}

}

Leave a Reply