Read numbers between 0-999 and returns number in words

program to convert a given number to words
convert number to words python
python convert numbers to letters
program to convert a given number to words in java
java program to display number in words
convert number to words java example
convert decimal number to words in java
java program to convert number to words using switch case

I am creating a program that reads numbers between 0-999 and then returns that number in words. I have got all other numbers working but I can't figure out how to get numbers between 111 - 119, 211 - 219, 311 - 319 and so on all the way to 911 - 919. Can you anyone help? Thanks!

I have tried changing numones = number%10; to numones = number%100; but that fails to read all other numbers and causes an array outofbounds error.

public static void main(String[] args) {
int numones;
    int numtens;
    int numhundreds;
    String [] ones = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
        "eleven", "twelve", "thirteen", "fourteen", "fiveteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};
    String [] tens = {"","", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};

    System.out.print("Number: ");
    int number = In.nextInt();
    while(number !=- 1) {
        if (number >= 100 && number <= 999) {
            numhundreds = number / 100;
            numtens = number/10%10;
            numones = number%10;
            if (number == 100 || number == 200 || number == 300 || number == 400 || number == 500
            || number == 600 || number == 700 || number == 800 || number == 900){
               System.out.println("" + ones[numhundreds] + " " + "hundred");
               System.out.print("Number: ");
               number = In.nextInt();
           }else{
            System.out.println("" + ones[numhundreds] + " " + "hundred and " + tens[numtens] + " " + ones[numones]);
            System.out.print("Number: ");
            number = In.nextInt();
           }
       }
   }
}

}

When 111 is entered, the output is one hundred and one when it should be one hundred and eleven.

You need to check if the number in the tens is equal to 1 and can do something like this:

if (numtens == 1)
{
    System.out.println(... + ones[numones + 10]);
} else {
    System.out.println(... + tens[numtens] + ones[numones]);
}

I would've gone with this kind of approach, as it is very easy to scale to larger numbers.

StringBuilder sb = new StringBuilder();

if (numhundreds > 0)
{
    sb.append(ones[numhundreds] + " hundred");
    if (numtens > 0 || numones > 0) sb.append(" and ");
}

if (numtens == 1)
{
    sb.append(ones[10 + numones]);
} else if (numtens > 1){
    sb.append(tens[numtens]);
    if (numones > 0) sb.append(" ");
}

if (numones != 0 && numtens != 1)
{
    sb.append(ones[numones]);
}

String result = sb.toString();

System.out.println(result);

Program to convert a given number to words, The code supports numbers up-to 4 digits, i.e., numbers from 0 to 9999. Idea is to create arrays that store individual parts of output strings. One� Following is the implementation for the same. The code supports numbers up-to 4 digits, i.e., numbers from 0 to 9999. Idea is to create arrays that store individual parts of output strings. One array is used for single digits, one for numbers from 10 to 19, one for 20, 30, 40, 50, .. etc, and one for powers of 10.

First of all, instead of this long "if" statement:

if (number == 100 || number == 200 || number == 300 || number == 400 || number == 500
        || number == 600 || number == 700 || number == 800 || number == 900)

You could just check if dividing the number by 100 has no remainder, like so:

if(number%100==0)

Because 100%100=0, 200%100=0, 300%100=0 ...

Now just like Rishaan said, you need to check if "numtens" value is 1, you can also do that inside the print statement using a conditional operator:

else{
     System.out.println("" + ones[numhundreds] + " " +
     "hundred and "+ (numtens == 1 ? ones[numones+10] : tens[numtens] + " " + ones[numones]));     
     System.out.print("Number: ");
     number = In.nextInt();
   }

Printable Numbers In Words Chart, Show Numbers As Words. Numbers In Words Chart - 0 to 100 Number, In Words NUMBERS TO WORDS script by Milorad Ivovic (ivovic.net) - GPL In this range, read and write numerals and represent a number of objects with a Numbers Chart - From 10 to 999 Numbers : Adjustable Start Number, Interval, and� Enter the decimal number in the box to the right of the decimal point. Type the number in the box and then click "Click to Convert" If the number is 346,894 then type "346,894" (no quotation marks). Do not type a decimal point. If the number is 2154 you may type "2,154", you may type the comma. Type "2,154".

Two case were missing namely "... and [tens]" and "[tens]":

public static void main(String[] args) {
    int numones;
    int numtens;
    int numhundreds;
    int twenties;
    String [] ones = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
        "eleven", "twelve", "thirteen", "fourteen", "fiveteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};
    String [] tens = {"","", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
    Scanner In = new Scanner (System.in);
    System.out.print("Number: ");
    int number = In.nextInt();
    while(number !=- 1) {
        if (number >= 100 && number <= 999) {
            numhundreds = number / 100;
            numtens = number/10%10;
            numones = number%10;
            twenties = number%100;
            System.out.println("Nbr"+number+" "+numtens);
            if (number == 100 || number == 200 || number == 300 || number == 400 || number == 500
            || number == 600 || number == 700 || number == 800 || number == 900){
               System.out.println("" + ones[numhundreds] + " " + "hundred");
               System.out.print("Number: ");
               number = In.nextInt();
           }else if(number%100<20 && numtens==1){
                System.out.println("" + ones[numhundreds] + " " + "hundred and " + ones[twenties]);
                System.out.print("Number: ");
                number = In.nextInt();
           }else{
            System.out.println("" + ones[numhundreds] + " " + "hundred and " + tens[numtens] + " " + ones[numones]);
            System.out.print("Number: ");
            number = In.nextInt();
           }
        }else{
            twenties = number%100;
            System.out.println("" +ones[twenties]);
            System.out.print("Number: ");
            number = In.nextInt();
        }

   }
}

Convert number to words using java program, Problem Write a program in java which reads a number from the console and Program to convert the number entered in digits to its word representation is given if (number == 0) { return "zero"; } // add minus before conversion if the number� Read numbers between 0-999 and returns number in words. Vis Team March 30, 2019. I am creating a program that reads numbers between 0-999 and then returns that number

How to Convert Math Number to Equivalent Readable Word in Java , What if someone asks you a java program for writing numbers in words . Read Also : Length of String without using length() method Taking three digits at a time from right to left , we will scan the whole input number until it is fully + current; } public String convert(int number) { if (number == 0) { return "zero"; } String� Choose to have words for the numbers in lowercase, uppercase or title case to easily copy and paste to another application. This converter will convert numbers to words and figures to words. The number to words can be done for real numbers and Scientific E Notation. Limited to use of 90 characters and 1e-90 and 1e+90. References for Number Names

How to convert numbers to words in Python, How can I get the 3rd largest number from a list in Python? 12,484 Views If num<20, we can just read it out directly. Write a java program to convert numbers into words? return Words(n//100) + " Hundred " + (Words(n % 100) if n % 100. This is my first post, and i'm currently struggling with creating a program which can transform the input of a number into its respective word. My code so far is written below, i can't seem to get the tens to work properly i.e 21,31,41,51 etc..

Java program to convert numbers to words � GitHub, return convert(n / 1000) + " Thousand" + ((n % 10000 != 0) ? s=new Scanner( System.in); System.out.println("Enter a number to convert into word format"); n =s. Numbers in words are written usually with the help of the English alphabet. For example, 100,000 in words is written as 1 Lakh or One hundred thousand. Earlier, Roman numerals were used to represent the numbers by Romans such as (1-I, 2-II, 3-III, 4-IV, and so on).