Number Name in JAVA

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


Program Video : Watch Now



 

All the Best :)
Keep Learning :)
 

Comments

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA