Convert Numbers To Words in Java

By | April 26, 2016

Code To Convert Numbers To Words in Java Programming

Here’s a Code To Convert Numbers To Words in Java Programming Language. This Java Code To Convert Integers into Words makes use of Concatenation Operation using String Object in Java.

Also Read: Java Program To Draw A Circle in AWT

Code To Convert Numbers To Words in Java using Concatenation

import java.io.*;
import java.util.*;

public class converter 
{
    String num;
    String disp = "nConversion from Number to Words:n";

    void input()
    {
        System.out.println("nEnter The Number:n");
        Scanner cr = new Scanner(System.in);
        num = cr.nextLine();
    }

    public void output()
    {
        int count;
        char choice;
        for(count = 0;count < num.length();count++)
        { 
            choice = num.charAt(count);
            switch(choice)
            {
                case '0': disp = disp.concat("nZeron");
                      break;
                case '1': disp = disp.concat("nOnen");
                      break;
                case '2': disp = disp.concat("nTwon");
                      break;
                case '3': disp = disp.concat("nThreen");
                      break;
                case '4': disp = disp.concat("nFourn");
                      break;
                case '5': disp = disp.concat("nFiven");
                      break;
                case '6': disp = disp.concat("nSixn");
                      break;
                case '7': disp = disp.concat("nSevenn");
                      break; 
                case '8': disp = disp.concat("nEightn");
                      break;
                case '9': disp = disp.concat("nNinen");
                      break;
                default: System.out.println("nPlease Enter A Proper Numbern");
            }           
        }
        System.out.println(disp);
    }

    public static void main(String [] args)
    {
        converter obj1 = new converter();
        obj1.input();
        obj1.output();      
    }
}

Also Read: Java Program To Count Occurrence of Character in Strings

 

If you have any Compilation Errors with this Code To Convert Numbers To Words in Java, Mention it in the Comment Section.

Let's Discuss