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

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

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

View Answers

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









Related Tutorials/Questions & Answers:
Java program - convert words into numbers?
Java program - convert words into numbers?   convert words into numbers?   had no answer sir
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
Advertisements
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 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
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
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
Prime numbers in Java between 1 and 100
numbers in java between 1 and 100: package net.roseindia; /* * This program...Prime numbers in Java between 1 and 100  Hi, How to display prime numbers in java between 1 and 100? Thanks   Hi, Prime numbers
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 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
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
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
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 program, we have used two 'for' loop. For loop will start from 1 to entered... of the java Program to get prime numbers: import java.io.*; class
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..., which automatically prints Prime Number starting from 1 to 50. Example
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
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 list even numbers between 1 and 100?
How to list even numbers between 1 and 100?  Hi, I Java to check if a number is even? How to list even numbers between 1 and 100? Thanks  ... the numbers between 1 and 100 for (int i=1;i <=num ; i++){ if(i%2==0
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
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
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
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
Generate array of random numbers
. In this section, we are going to accept 10 numbers and display 5 numbers from them...:ADS_TO_REPLACE_1 Enter 10 numbers: 1 2 3...Generate array of random numbers You can generate a random number either
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
Prime Numbers from range
Prime Numbers from range  how to find prime numbers in a given range...(); int index1=0; int index2=number.length()-1; char x...; if (index2-index1==0 || index2-index1==1) list.add(i); index1
ModuleNotFoundError: No module named 'words-from-grid'
ModuleNotFoundError: No module named 'words-from-grid'  Hi, My... named 'words-from-grid' How to remove the ModuleNotFoundError: No module named 'words-from-grid' error? Thanks   Hi, In your python
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 java series
printing java series  * *** ***** ******** ***** *** *   Post the format properly
program to display all words in the file in the sorted order without duplicates
program to display all words in the file in the sorted order without duplicates  I want a java program which accepts a file from user and displays all words in the file in the sorted order without duplicates
Java program using stateful session - Java Beginners
Java program using stateful session   Write a program using stateful session bean to add three numbers by accepting input from the user
connect ftp from java program
connect ftp from java program  Hi, I need to connect to the ftp and get the files through a java program.. I wrote the following code... import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile
connect ftp from java program
connect ftp from java program  Hi, I need to connect to the ftp and get the files through a java program.. I wrote the following code... import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile
WAS server configuration from JAVA program
WAS server configuration from JAVA program  How to get web sphere server status like heap,connection pool properties,stall counts etc. from a java applciation
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
read a positive real numbers from highest to lowest
read a positive real numbers from highest to lowest  write a java program that will read a sequence of 10 positive real nos. entered by the user and will print the same numbers in sorted order from lowest to highest using arrays
How to create the program in Java for getting the forgotten Password Form?
How to create the program in Java for getting the forgotten Password Form?  Hi, Our enterprise application requires the development of a form... to the user on email address. How to create the program in Java for getting
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
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
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers       Java Even Numbers - Even Numbers Example in Java: Here you will learn to write a program for listing out
send multiple textbox vaues in to an jsp form to store them in a DB table
send multiple textbox vaues in to an jsp form to store them in a DB table  Hi sir... I am not getting how can i send the multiple input text box... in to an database table. Please help me...... looking forward to hear from you
Program to display palindrome numbers between some range
Program to display palindrome numbers between some range  Hi!I want a java program to display palindrome numbers between 100 to 1000.can you please...; int index2=number.length()-1; char x=number.charAt(index1
printing series in java
printing series in java  1 123 12345 1234567 12345 123 1   Here is a code for the following pattern: 1 123 12345 1234567 12345 123 1 class Pattern{ public static void main(String[] args
Calculator program in Java
Calculator program in Java is used by programmer to add, subtract, multiply or divide two integer numbers that are input by system. In the given example... program in Java package Tutorial; import java.io.*; class calculator
Java Find Automorphic numbers
Java Find Automorphic numbers In this section, you will learn how to find the automorphic numbers between 1 and 1000. Automorphic numbers are the numbers... of number 6 at the end. Here we are going to find the automorphic numbers between 1
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
prime numbers - Java Beginners
prime numbers  Write a java program to find the prime numbers between n and m

Ads