Java Program for accepting numbers from 1 - 999 and printing them in form of words
1 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners

Program for accepting numbers from 1 - 999 and printing them in form of words

May 7, 2012 at 1:23 PM

Java Convert Number to Words

The given code accept numbers from 1 to 999 and convert them to words. For example, 1 is to be displayed as one.

```public class ConvertNumberToWords {

final private  static String[] units = {"Zero","One","Two","Three","Four",
"Five","Six","Seven","Eight","Nine","Ten",
"Eleven","Twelve","Thirteen","Fourteen","Fifteen",
"Sixteen","Seventeen","Eighteen","Nineteen"};
final private static String[] tens = {"","","Twenty","Thirty","Forty","Fifty",
"Sixty","Seventy","Eighty","Ninety"};

public static String convert(Integer i) {
if( i < 20)  return units[i];
if( i < 100) return tens[i/10] + ((i % 10 > 0)? " " + convert(i % 10):"");
if( i < 1000) return units[i/100] + " Hundred" + ((i % 100 > 0)?" and " + convert(i % 100):"");
if( i < 1000000) return convert(i / 1000) + " Thousand " + ((i % 1000 > 0)? " " + convert(i % 1000):"") ;
return convert(i / 1000000) + " Million " + ((i % 1000000 > 0)? " " + convert(i % 1000000):"") ;
}
public static void main(String[]args){
for(int i=1;i<1000;i++){
System.out.println(i+" \t "+convert(i));
}
}

}
```

If you want to convert big numbers, then go through the following link:

Java Convert Numbers to Words

Java program - convert words into numbers?
Java program - convert words into numbers?   convert words into numbers?   had no answer sir
Java program for printing document
Java program for printing document  can u send me the java program for printing the office document? email: [email protected]
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
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
Printing numbers in pyramid format - Java Beginners
Printing numbers in pyramid format  Q) Can you please tel me the code to print the numbers in the following format: 1...[] args) throws Exception{ int k = 1; for(int i=1; i<= 4 ;i++){ for(int j=1; j
Generate random numbers from 1 to 100
Generate random numbers from 1 to 100  1)A class Called: RandomNumberGenerator that generate random numbers from 1 to 100 2)A class Test that tests... an object from the Random NumberGenerator class to generate your input test data
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
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
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
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
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
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... Tell Me This Program.  Here is an example that reverse the words
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 program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
Printing numbers up to N into a file
Printing numbers up to N into a file  I'd like to print the first N integers, that is, "1, 2, 3, 4, ..., N-1, N", say N equals 1000, or 10000 or whatever. I'd also like to have the result stored as a file instead of having
Write a JSP program to display the grade of a student by accepting the marks of five subjects.
Write a JSP program to display the grade of a student by accepting the marks of five subjects.  Write a JSP program to display the grade of a student by accepting the marks of five subjects
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 scanner class reads the string from the console. After initializing a counter, we
Prime Number in Java
a Java program to get prime numbers between 1 to the desired number. To start... the bytes. In this example of writing java program to get prime numbers, we... have used two 'for' loop. For loop will start from 1 to entered number
Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any... than 1 or itself. Similar logic is used in program will displaying the result... automatically prints Prime Number starting from 1 to 50. Example of Prime Number
printing in java
printing in java  hello i want to print a jInternalframe containing some lebels,but my printer sent me a paper with the following written...://www.roseindia.net/java/example/java/swing/Print.shtml Thanks
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
Pass values from form to form
Pass values from form to form       Java program to pass values from one form to another form... used in to the different applications. Here in the JSP (Java Server Pages) we
how to write a program in java to print numbers in equalateral triangle
how to write a program in java to print numbers in equalateral triangle  the output must be 1 324 76589   Here is an example of pattern 1 2 3 4 5 6 7 8 9 Example: public class NumberTriangle{ public
how to draw multilple circles in a circular form and connect them with lines - Java Beginners
how to draw multilple circles in a circular form and connect them with lines  Hi, Can anyone explains me , how to draw multiple circles using a single applet or swings in a circular form and connect them with lines. It should
printing java series
printing java series  * *** ***** ******** ***** *** *   Post the format properly
PHP Form, PHP guest form
will recieve them and simultaneuously delete them from the server. Realization...PHP email form HTML form It's not a good idea to leave your private e.... But nevertheless you need some way to get feedback from your visitors. In the three parts
printing records from jsp - JSP-Servlet
printing records from jsp  Hi Plz tell me how to printing out pages from jsps with page numbers Thank you  Hi friend, For paging in Jsp visit to : http://www.roseindia.net/jsp/paging.shtml http
Java Printing - Java Beginners
Java Printing  Can anybody plz help in giving the code for printing... urgetn.. Printing means sending the document to the Printer..  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example
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
printing example - Java Beginners
printing example  Is it possible to print java controls using print method? My problem is to print a student mark list using java? The mark list should like that of university mark list
Generate array of random numbers
. In this section, we are going to accept 10 numbers and display 5 numbers from them...: Enter 10 numbers: 1 2 3 4 5...Generate array of random numbers You can generate a random number either
Tutorials