top of page
Writer's pictureSatyam Gupta

Number Name Program in JAVA

Updated: Mar 11, 2021

Number Name in JAVA

Write a Program to input a number and Display it in Words


Note : Entered number should be between 0 and 99 


Example : Input    : 79

                 Output  : Seventy Nine 

Input    : 85

                 Output  : Eighty Five

 

Algorithm and Program given below :-

Algorithm :-

  • Input a Number

  • Declare two String type Array (let say two array be named as One[] and Ten[])

  • Enter Number Name till nineteen in One[] array according to the respective position

  • In Ten[] array leave first two position (i.e. 0th and 1st) as blank space

  • Enter names from 2nd position till 9th Position (like twenty, thirty, forty etc)

  • Now, If entered number is greater than 19 than print

  • System.out.println( Ten[n/10] + " "+ One[n%10]);

  • Otherwise Print only One[n]

 

Program :-


import java.io.*; import java.util.*; class Word {     public static void main(String args[])     {         Scanner in= new Scanner(System.in);         int n; // variable for taking input number         System.out.println("Enter Number");         n=in.nextInt();  // Input Number          String one[] = { "Zero", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine", " Ten",                 " Eleven", " Twelve", " Thirteen", " Fourteen", "Fifteen", " Sixteen", " Seventeen", " Eighteen",                 " Nineteen" };         String ten[] = { " ", " ", " Twenty", " Thirty", " Forty", " Fifty", " Sixty", "Seventy", " Eighty", " Ninety" };         if (n > 19)         {             System.out.println(ten[n / 10] + " " + one[n % 10]);         }         else         {             System.out.println(one[n]);         }     } // end of main method } // end of class

 

Note : The program is written in the easiest way possible so try to understand it. If you face any problem in understanding this program than feel free to contact/comment.


Source Code : Click here

Program Video : Watch now




All the Best :)

Keep Learning :)

64 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page