Share on Google+Share on Google+

java beginners
1 Answer(s)      7 years ago
Posted in : Java Beginners

to Write a program to convert entered number into words.
Output : You have entered number = 356
The number in words is = three five six.



View Answers

January 18, 2010 at 4:45 PM

Hi Friend,

Try the following code:

import java.util.*;
public class NumberToWords{
static final String[] Number1 = {""," Hundrad"};
static final String[] Number2 = {"","One","Two", "Three","Four","Five",
" Six"," Seven", "Eight"," Nine","Ten" };
String number(int number){
String str;
if (number % 100 < 10){
str = Number2[number % 100];
number /= 100;
else {
str= Number2[number % 5];
number /= 5;
if (number == 0) return str;
return Number2[number] + "hundred" + str;
public String convert(int number) {
if (number == 0){
return "zero";
String pre = "";
String str1 = "";
int i = 0;
do {
int n = number % 100;
if (n != 0){
String s = number(n);
str1 = s + Number1[i] + str1;
number /= 100;
while (number > 0);
return (pre + str1).trim();
public static void main(String[] args) {
NumberToWords number = new NumberToWords();
Scanner input=new Scanner(;
System.out.println("Enter four digit Number: ");
int n=input.nextInt();
Character c1 = new Character(Integer.toString(n).charAt(0));
Character c2 = new Character(Integer.toString(n).charAt(1));
Character c3 = new Character(Integer.toString(n).charAt(2));
Character c4 = new Character(Integer.toString(n).charAt(3));

System.out.print( number.convert(Integer.parseInt(c1.toString()))+" "+number.convert(Integer.parseInt(c2.toString()))+" "+number.convert(Integer.parseInt(c3.toString()))+" "+number.convert(Integer.parseInt(c4.toString())));



Related Tutorials/Questions & Answers:
Beginners in Java
Beginners in Java  Hi, I am beginners in Java, can someone help me... tutorials for beginners in Java with example? Thanks.   Hi, want to be command over Java, you should go on the link and follow the various beginners
java beginners - Java Beginners
the following links: beginners  what is StringTokenizer? what is the funciton
Java for beginners
Java for beginners  Java for beginners Which is the best resource... Java video tutorial for beginners. Thanks   Hi, Here are the best resources for Learning Java for beginners: Java Video tutorial Java tutorials
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
programming - Java Beginners
programming for java beginners  How to start programming for java beginners
Java for beginners - Java Beginners
:// Thanks...Java for beginners  Hi! I would like to ask you the easiest way to understand java as a beginner? Do i need to read books in advance
Good tutorials for beginners in Java
Good tutorials for beginners in Java   Hi, I am beginners in Java... in details about good tutorials for beginners in Java with example? Thanks.   ... the various beginners tutorials related to Java
Java - Java Beginners
Java  how to declare arrays   Hi Friend, Please visit the following link: Thanks
basic java - Java Beginners
basic java  oops concept in java ?  Hi Friend, Please visit the following links: Thanks
java - Java Beginners
java  ...can you give me a sample program of insertion sorting... with a comment,,on what is algorithm..   Hi Friend, Please visit the following link:
java - Java Beginners
java  HOW AND WHERE SHOULD I USE A CONSTRUCTOR IN JAVA PROGRAMMING???   Hi Friend, Please visit the following links:
java - Java Beginners
links:  write a java program that will read a positive integer
Tutorial For Java beginners
Tutorial For Java beginners  I am beginners in Java. Is there any good tutorial and example for beginners in Java? I want to learn Java before Jan... of December 2013. Check the Java Beginners Java Tutorial section for tutorials
java downloads - Java Beginners
information. downloads  hi friends, i would like to download java1.5 .so if possible please send the link for java1.5 free download  Hi friend
java - Java Beginners
java  hi!! i want 2 download jdk latest version so can u pls send me the link..?  Hi Friend, Please visit the following link: Thanks
Program - Java Beginners
Program Java link list  I need program in Java to copy a file to another file  Hi Friend,For more information
java beginners - Java Beginners
java beginners   pl. give few example program of signed and unsigned integer bye
Java basics - Java Beginners
:// for more code and examples on Java...literals in java program  Why we use literals in java program?  Hello,A literal is the source code representation of a fixed value
java beginners - Java Beginners
java beginners   pl. tell me in System.out.print() what is System , what is out , print is method name . is System is a package of class name thanks   Hi Friend, System: It is a standard java class
Queue - Java Beginners
Queue  i'm working with queue on java. since im beginners im asking for additional example programs on queue using java to enhance my knowledge. thanks so much for the help! God bless
Java - Java Beginners
: Thanks...Java  How to add and print two numbers in a java program single...; System.out.prinln(a+b);   Hi friend, Code to add two number in java class
java beginners - Java Beginners
java beginners  pl. let me know the answers of the following questions : 1) A program is unable to create objects of a class declared globally. what could be the problem wtih this construcotr 2) what is the benefit
java beginners - Java Beginners
java beginners   pl. let me know how to exterat the decimal numbers from a number i want a java program for it Example if input 12.453 OUTPUT 12 .453 if input 25.7657 OUTPUT 25
java beginners - Java Beginners
java beginners  pl. let me know the java program to get the following patteren pl. can i I get it today itself . thank you regargd a a a a a a a a a a a a a and the bewlow
java beginners - Java Beginners
java beginners   let me know the java code for the followign patteren *00 **0 *** **0 *0 0 means space whereever the stars are there that is the pattern   class user { public static void main(String
java beginners - Java Beginners
java beginners   the patteren u received is not the actual patteren which i need the program i don't know why the patteren does not reach in proper formate to you . it was in upside down triangle form . at the top
java beginners - Java Beginners
java beginners   Q. 1 How is class related to data abstraction? Q. 2 what is the relationship between a class and an object? thanks  Hi Friend, 1)Data Abstraction is used to hide certain details that we
java beginners - Java Beginners
java beginners   what are real constant? give some example of real constant. which of the following is the valid real constant. 2.0, -16.0, +15/2, 1.9E, 189.E4, 0.67E3.6  Hi Friend, A real constant is a real
java beginners - Java Beginners
java beginners  please let me know what is the difference between signed and unsigned integer thanks regards bhavna   Hi Friend, Differences: 1)Signed integer can be a negative number whereas
java beginners - Java Beginners
java beginners  the pattern was not in this format * * * * * * * * * * * * * * * * it is like this * * * * * * * * * * * * * * * * thanks   Hi Friend, If you want the following
java beginners - Java Beginners
java beginners  thanks for the suggestion so I am sending the patteren in place of dots i want blank space aaaaaaaaaaaaaaaa a............a a........a a.....a a...a a thanks
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null