Home Tutorialhelp Comment More Enhancement, case 20,30,40 etc handled.

 
 

Comment

Raj
More Enhancement, case 20,30,40 etc handled.,
September 25, 2008 at 2:51 AM

public class NumberToWords{
static final String[] Number1 = {""," Hundred"};
static final String[] Number2 = {"","One","Two", "Three","Four","Five", " Six"," Seven", "Eight"," Nine","Ten" };
static final String[] Number3 = {"", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty","Ninety"};
static final String[] Number4 = {"", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};

String number(int number){
String str;
if (number % 100 < 10){
str = Number2[number % 100];
number /= 100;
}
else{
if( (number % 10) == 0){
return Number3[number / 10];
}
else{
if((number % 10) < 10){
str = Number3[number / 10];
number /=10;
}else{
str = Number2[number % 10];
number /= 10;
}
if (number == 0) return str ;
return str + " " + Number2[number] ;
}
}
if (number == 0) return str;
return Number2[number] + "hundred" + str;
}

private String convert(int number) {

if(number < 0 || number > 999)
return "Invalid Number - Should be (0-999)";

if (number == 0){
return "zero";
}
String pre = "";
String str1 = "";
int i = 0;
if( (number > 10 && number < 19)){
return Number4[ number % 10];
}else{
do {
int n = number % 100;
if (n != 0){
String s = number(n);
str1 = s + Number1[i] + " " + str1;
}
i++;
number /= 100;
}
while (number > 0);
}

return (pre + str1).trim();
}
public static void main(String[] args) {
NumberToWords num = new NumberToWords();
System.out.println("words is :=" + num.convert(13));
System.out.println("words is :=" + num.convert(200));
System.out.println("words is :=" + num.convert(999));
System.out.println("words is :=" + num.convert(10));
System.out.println("words is :=" + num.convert(179));
System.out.println("words is :=" + num.convert(44));
System.out.println("words is :=" + num.convert(900));
System.out.println("words is :=" + num.convert(9221));
}
}
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Programming Tutorials

Java Convert Number to Words
Java Convert Number to Words In this section, you will learn how to convert... to the usage. Through the given code, you can convert the large digit numbers into words...", "ninty" }; public String convert(int number) { int n = 1; int word 

Java Tips and Examples

Convert Number To Words
Convert Number To Words       In this example, We are going to convert number to words. Code...;   }   public String convert(int number 

Java Code Examples

Java Convert date to words
Java Convert date to words In this tutorial, you will learn how to convert date into words. Just like a number, you can also convert a date into words. Here we are going to convert the current date into words. For this, we have created 

General

Java Conversion
to convert number to words.    Degree Converter...Java Conversion      ... will learn to convert decimal number into binary. The java.lang package provides 

Java-Tutorials

Java : String Case Conversion
Java : String Case Conversion In this section we will discuss how to convert a String from one case into another case. Upper to Lower case Conversion : By using toLowerCase() method you can convert any upper case char/String 

Java Interview Questions

Java program - convert words into numbers?
Java program - convert words into numbers?   convert words into numbers?   had no answer sir 

Java Beginners

Number Convert - Java Beginners
Number Convert  Dear Deepak Sir, I am entered in Command prompt Some value like 234.Value can be convert into Two Hundred and Thirty Four Rupees...=""; while (count != 0){ switch (in){ case 1: num = count % 100; passString(num 

Java Beginners

java program to convert decimal in words
java program to convert decimal in words  write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve 

Java Beginners

String to Date Conversion - Java Beginners
)); For read more information : http://www.roseindia.net/java/java-conversion... but all those are giving me GMT etc. I just need the format 11/SEP/2008 07:07:32... 11-09-2008 07:32:AM Now I just need to convert this String variable value 

Java Beginners

Distance conversion - Java Beginners
in metres. The program will then present a user menu of conversion types, converting... the user. ? Write three methods to convert the distance to kilometres, feet and inches...{ System.out.println(); System.out.println("1. Convert to kilometers 

Java Technology Tutorials

Java count words from file
Java count words from file In this section, you will learn how to determine the number of words present in the file. Explanation: Java has provides several... by using the StringTokenizer class, we can easily count the number of words 

Java Beginners

java conversion
java conversion  how do i convert String date="Aug 31, 2012 19:23:17.907339000 IST" to long value 

General

Convert String to Number
Convert String to Number       In this section, we will learn how to convert String to Number. The following program provides you the functionality to convert String 

Java Beginners

convert to java plss - Java Beginners
convert to java plss  hi i am using microsoft VB6.0 and my friend ask me to make java program to convert number to words but i only use visual basic because i dont know much in java plss convert it to me this is my code 

Java Beginners

form to java script conversion
form to java script conversion  I am using a form one more form cotain a piece of code . how to convert it to java script to function it properly? code is shown below <form action="http://www.google.com" id="cse-search 

Java Interview Questions

java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file 

JavaScript Questions

Java sample using - for loop, if then else etc etc
Java sample using - for loop, if then else etc etc  sample program to produce summary information on sales report. The program will input Data of Salesman Id, Item code, and number of cuestomer. Sales id is 5digit long 

Java Tips and Examples

Conversion of Decimal to Binary in Java
Conversion of Decimal to Binary  in Java In this section we will discuss about conversion of Decimal to Binary in Java. You know that number having... be converted to binary and written as 1010. Example : Convert 12 into binary number 

JavaScript Questions

Number conversion in JavaScript
Number conversion in JavaScript  How do you convert numbers between different bases in JavaScript 

General

Java Conversion
 

Java Beginners

Java Conversion Question - Java Beginners
Java Conversion Question   Hello sir ,How i can Convert Java Code to Vb.net ,Plz Help Me 

Java Beginners

html2xml conversion
html2xml conversion  java code to convert html file to xml 

Java Beginners

Language Conversion
Language Conversion  write a java program to convert "Hello World" in spanish 

Java Beginners

Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding 

Applet Questions

conversion Applet
conversion Applet  I am a java beginner.................. strong texthow to create JApplet that prompts the user to enter a distance in miles... kilometers,where XX.XX is the number of kilometers. A mile is 1.6 kilometers 

General

Convert Byte to Hexadecimal
for this conversion. Code Description: This program takes a byte number from console.... C:\corejava>java ByteToHexa Enter the byte number... Convert Byte to Hexadecimal      

General

Convert Number to Roman Number Using Java
Java Convert Number to Roman Numerals In this section, you will learn how to convert the number to roman number.  To do this, we have created a class... and the method convertIntegerToRoman(int n) convert the specified number into roman 

Java Beginners

Type Conversion - Java Beginners
Type Conversion   Hai, rajanikanth, Please explain how to convert from integer value to a string value .In a database operation i want to convert... for conversion 

Java Beginners

indexof case insensitive java
indexof case insensitive java  Hi, I have to use the indexOf function on String class in Java. I am looking for indexof case insensitive java example. Share the code with me. Thanks   Hi, You can convert both 

JDBC Questions

Enhancement for connection pool in DBAcess.java
Enhancement for connection pool in DBAcess.java  package spo.db; import com.javaexchange.dbConnectionBroker.DbConnectionBroker; import java.io..... The modification are: -add a d detail log -add connection heading -more in info about 

Java Beginners

Conversion from color to Gray Image - Java Beginners
Conversion from color to Gray Image  Hi... Sakthi here.. i am new to java. and i haven't try this so far How to convert the color image to gray scale image in java? could u plz help me out to start the process 

Java Tips and Examples

Convert Number to String
Convert Number to String       In this section, we will learn how to convert numbers to String. The following program provides you the functionality to convert numbers to String 

Java Beginners

Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words
. print: the total number of words processed, the number of unique words, the N...Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words  I have to: 1.Retrieve 

General

Casting (Type Conversion)
are there in java. Some circumstances requires automatic type conversion, while in other cases... Java performs automatic type conversion when the type of the expression... in case of narrowing i.e. when a data type requiring more storage is converted 

Java Tips and Examples

Convert Number to Binary
Convert Number to Binary       In this section, you will learn to convert a number to a binary (0,1). The given number is a decimal format and the following program to calculate its 

Java Beginners

Java To Vb.Net Conversion - Java Beginners
Java To Vb.Net Conversion  How to convert Java Code To VB.net,which Software is useful to convert java to vb.net,plz Help Me 

General

Count numbers of spaces and number of words from the input string
Count numbers of spaces and number of words from the input string Java In this section, you will learn how to count the number of spaces and words from... the number of spaces. Now, in order to count the number of words, we have splitted 

General

Convert One Unit to Another
, Liters, Miles, Carats, Meters etc to convert them to another units. First... C:\unique>java UnitConverter1 Conversion Table... Convert One Unit to Another      

Java Beginners

number of stairs - Java Beginners
number of stairs  1. Write a program that prints an n-level stair case made of text. The user should choose the text character and the number...(); } } } ----------------------------------- read for more information, http://www.roseindia.net/java/master 

Java Beginners

Excel conversion tool. - Java Beginners
Excel conversion tool.  Hi, I need a conversion tool which can convert .xls(Excel 2003) to .xlsx (Excel 2007) and vice-versa. Please suggest any links ro tools. Thank You 

Java Beginners

how to handle action events in case of more than one JFrame
how to handle action events in case of more than one JFrame   I have downloaded a snake game project from the internet, initially this project contains three java files namely 1. Engine.java 2. Snake.java 3. Gameoard.java when i 

Core Java Tutorials

Java String Case Converter
Java String Case Converter Here we are going to convert lowercase characters to upper case and upper case characters to lower case simultaneously from.... If there is a lowercase character then convert it into uppercase using Character.toUpperCase(ch[i 

General

List of Java Exception
List of Java Exception       Exception in Java are classified on the basis of  the exception handled by the java compiler. Java consists of the following type of built 

General

List of Java Exception
; the exception handled by the java compiler. Java consists of the following type... List of Java Exception     .... This exception is thrown when there is an error in input-output operation. In this case 

Development process Questions

Conversion - Development process
Conversion Assistant (JLCA). Code that calls Java APIs can convert to comparable C# code...Conversion  Why is there a need to convert from Java to .NET? What is the theory of conversion from java to .NET? How it is done?   Hi 

Java Beginners

putting words to line number form a java file/test file and show occurrence
putting words to line number form a java file/test file and show occurrence  hi all i want putting words to line number form a java file and show... and BinarySearchTree and please help me in java coding 

Java Tips and Examples

Switch case in java
Switch case in java In this section we will learn about switch case in java..., and java, switch case is used . switch  is a selection control mechanism used... will illustrate the use of switch case in java: import java.util.Scanner; public 

Java Beginners

ascii to thai language conversion - Java Beginners
ascii to thai language conversion  I have a string in ascii format like \u0042\u00072 ..., It was converted from thai language. How can i convert it to thai language. I would be more thankful if I get some example or some 

Java Beginners

java Application Convert to java Applet
java Application Convert to java Applet  Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet...(); System.out.println(); switch(menu) { case 1: System.out.print("Enter Number of Day 

Java Interview Questions

how to count words in string using java
++; } System.out.println("Number of words are: "+count); } } Thanks   Hello...how to count words in string using java  how to count words in string... count=0; String arr[]=st.split(" "); System.out.println("Number 

Java Beginners

PDF to Word Conversion - Java Beginners
PDF to Word Conversion  Hello, Can we convert a PDF document to Microsoft word document thru Java. If its not possible in Java, is it possible in any other language 

Date Calendar

Java Date conversion - Date Calendar
Java Date conversion  How do I convert 'Mon Mar 28 00:00:00 IST 1983' which is a java.util.Date or String to yyyy/MM/dd date format in sql 

Java Beginners

from number to word
from number to word  i want to know weather there is any method that can be use in changing value from number to word. Example if i write ten thousand, it will automatically be written as 10000.   Java convert number 

General

Java Date Conversion
Java Date Conversion In java date conversion, two packages are used... Java Converts String into Date In this example we are going to convert...; used to convert between dates and time fields and the DateFormat class 

Java Interview Questions

Conversion In Collections - Java Interview Questions
Conversion In Collections  Hi Friends, can u give code to convert... Friend, 1)Convert ArrayList To HashMap: import java.io.*; import java.util....)Convert HashMap To ArrayList: import java.util.*; public class 

Java Beginners

Another distance conversion - Java Beginners
Another distance conversion  Write an application that reads a distance in metres. The program will then convert the distance to kilometres, feet... a method for each conversion ? toKilometres(), toFeet(), and toInches 

Java Beginners

Reports to pdf conversion
Reports to pdf conversion  I need to convert reports into pdf format using java.. Will i get any sample code 

Java-Tutorials

Switch Case in Java
version of Java did not support String in switch/case. Switch statements works... A statement in the switch block can be labeled with one or more case or default labels... case will take place. Example of Switch Statement in Java: import java.io. 

General

Collection of Large Number of Java Sample Programs and Tutorials
Collection of Large Number of Java Sample Programs and Tutorials Java Collection Examples Java 6.0 New Features (Collection Framework... ArrayLists, LinkedLists, HashSets, etc. A collection 

Java Beginners

How to convert a String to an int?
); Check more tutorials: Convert a String into an Integer Data Many examples of data conversion in Java. Thanks...How to convert a String to an int?  I my program I am taking 

Java Beginners

How to convert long to hexadecimal - Java Beginners
/java/java-conversion/HexadecimalToBinaryAndLong.shtml Thanks...How to convert long to hexadecimal  Dear all, anyone know how to convert long data to hexadecimal, please send me the information. Thanks  

Java Beginners

pdf to xml conversion
pdf to xml conversion  i want to convert pdf file into xml file.. where i am having a table in pdf file with some headers and some data into it. i want the headers to be the tag of xml file. how can i do that using java? please 

Java Beginners

HSSFCell to String type conversion
HSSFCell to String type conversion  Hello, Can anyone help me convert HSSFCell type to string. There is a solution in the following URL...://www.roseindia.net/tutorial/java/poi/readExcelFile.html 

Java Beginners

A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer 

Java Beginners

A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer 

Java Beginners

A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer 

Java Beginners

A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer 

Java Beginners

A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer 

General

Number Format Exception
.  A Number Format Exception occurs in the java code when a programmer tries to convert a String into a number. The Number might be int,float or any java... Number Format Exception      

Java Tips and Examples

Convert Hexadecimal number into Integer
Convert Hexadecimal number into Integer ... to convert hexadecimal data into integer. The java.lang package provides the functionally to convert the hexadecimal data into an integer type data.  Code 

Core Java

Java integer to string
/java/java-conversion/convert-number-to-string.shtml  ...; Many times we need to convert a number to a string to be able to operate...;toString()" method can also be used for the conversion. Read more at: http 

General

How to format number in Java?
Learn about the code of formatting the number in Java This tutorial explains you how to format the number in Java. There are number of situations where we... the number such as leading zeros, prefixes, group separators etc... Here we 

Java Beginners

computer manufacture case study
computer manufacture case study  Computer Manufacturer Case Study BNM... Wireless Mouse 4790 Lotus Notes 6000 Wireless Keyboard 9482 Sun Java Communications... address etc. The system should be flexible enough so that additional details 

Java Beginners

object conversion - Java Beginners
/java-conversion/ObjectToDouble.shtml Thanks... sandeep kumar suman...object conversion   Hi, Can anybody tell me the object conversion in java.   Hi sandeep Can u please tell me in details about your 

Java Beginners

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Beginners

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Beginners

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Beginners

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Server Faces Questions

how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...); System.out.println(); switch (question) { case 'a': AppendElement(); case 'b': AddElementSpecific(); case 'c 

Java Beginners

test case
test case  Hi Can you explain me how to write test case in java. regards kennedy 

Java Beginners

String conversion
String conversion  I want to convert a string of mix cases(lower and upper case) to vice versa. ex. HellO should be printed to hELLo. the string comes from user using datainputstream. Also sending individual chars of string 

Development process Questions

java code for conversion of arraylist to string - Development process
java code for conversion of arraylist to string  Hi, i have an arraylist contains [a,b,value,c,d,value]when ever value comes it will split into seperation.fo that i want to convert into string, after that split the string 

Java Beginners

Convert to java - Java Beginners
Convert to java  Can anyone convert this javascript program codes to Java codes,please...thanks! var iTanggalM = 0; var iTanggalH = 0; var...) { case 2 : { sDate = sHariE+", "+iTanggalM+" "+sBulanE+" "+iTahunM;break 

Java Beginners

convert date month and year into word using java
]; } public String convert(int number) { int n = 1...; case 4: word = number % 100...); } number /= 100; break; case

Java Beginners

convert date month and year into word using java
]; } public String convert(int number) { int n = 1...; case 4: word = number % 100...); } number /= 100; break; case

Java Beginners

conversion
conversion  please give me the code to convert the particular string "messageType=3+sourceSystemId=0+destinationSystemId=0+NPA=1+prefix=0+phoneNumber=0+length=0+subLength=209+subCode=49+subType=1+subResult=0+subCause=0 

Java Beginners

conversion
conversion  please give me the code to convert the particular string "messageType=3+sourceSystemId=0+destinationSystemId=0+NPA=1+ prefix=0+phoneNumber=0+length=0+subLength=209+subCode=49+subType=1+ subResult=0+subCause=0 

Java Beginners

Matching Case
Matching Case  Hi, i want some code for matching case from an text file. i.e if i give an query called Java from the user,i need to get an output searching the text file all the names in that without case sensitive 

Java Code Examples

Java reverse words in a string using only loops
Java reverse words in a string using only loops In this tutorial, you will learn how to reverse words in a string without using any inbuilt methods like split() etc, StringTokenizer functiom or any extra ordinary function Only loops 

Java Beginners

Java is case sensitive
Java is case sensitive  hello, Why Java is case sensitive?   hii, Java is Platform Independent Language, so its used widely in very big... that huge no of variables,Java is Case Sensitive 

Development process Questions

highlight words in an image using java
highlight words in an image using java  Hai all,In my application left side image is there and right side an application contains textboxes like... want to highlight name in the image using java/jsp/javascript.please help me 

Advertisements Advertisements
 

 

 

DMCA.com