Let us see how to convert number to word.
single digit: A digit or symbol starts with {0,1,2,3,4,5,6,7,8,9}.
Two digit:A digit or symbol starts with {10,11,12.....99}
multiples of ten+single digit=remaining all the two digit numbers.
as we know that the number ends with zero are multiples of ten.
Java Code for Number to Word Conversion
import java.util.Scanner; class Solution { public static void main(String args[]){ Scanner sc=new Scanner(System.in); System.out.println("enter the number"); int n=sc.nextInt(); int n1=n,n2=n; int b=n1%10,a=n2/10; // n1/10 means last digit is removed and n2%10 means last digit by modulus String[] single_digits = new String[]{"zero","one","two","three","four","five", "six","seven","eight","nine"}; String[] two_digits = new String[]{"","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen", "nineteen"}; String[] tens_multiple = new String[]{"","","twenty","thirty","forty","fifty","sixty", "seventy","eighty","ninety"}; if(a==1) { System.out.println(two_digits[b+1]); } else if(b==0) System.out.println(tens_multiple[a]); else System.out.println(tens_multiple[a]+"-"+single_digits[b]); }//main }
enter the number 3 -three 45 forty-five 90 ninety