Showing posts with label number to words in java. Show all posts
Showing posts with label number to words in java. Show all posts

Sunday, July 19, 2015

Number to Words in Java

A simple program that I wrote that will ask the user to enter decimal number and then our program will translate the given number into words using Java programming language.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

// numbers_words.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 19, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com

import java.util.Scanner;

public class numbers_words {

      

public static void main(String args[]) {
   
            Scanner input = new Scanner(System.in);
            char ch;
            
        do {
       int value=0,thousands=0,hundreds=0,tens=0,ones=0,zero=0,elevens=0;
             
    
        System.out.print("\t NUMBERS TO WORDS  ");
        System.out.println();
    System.out.print("Kindly Give a Number :  ");
        value = input.nextInt();

    if (value==0){

    switch (value){
    case 0: System.out.println("Zero");break;

    }
    }

    if ((value>=100) && (value<=10000)){

    thousands = value/1000;
    value = value%1000;
    hundreds = value/100;
    value= value%100;

    switch(thousands){

    case 1:System.out.print("One Thousand ");break;
    case 2:System.out.print("Two Thousand ");break;
    case 3:System.out.print("Three Thousand ");break;
                                case 4:System.out.print("Four Thousand ");break;
    case 5:System.out.print("Five Thousand ");break;
                                case 6:System.out.print("Six Thousand ");break;
    case 7:System.out.print("Seven Thousand ");break;
                                case 8:System.out.print("Eight Thousand ");break;
                                case 9:System.out.print("Nine Thousand ");break;
    case 10:System.out.print("Ten Thousand ");break;
    }


    switch (hundreds) {
    case 1:System.out.print("One Hundred ");break;
    case 2:System.out.print("Two Hundred ");break;
    case 3:System.out.print("Three Hundred ");break;
    case 4:System.out.print ("Four Hundred ");break;
    case 5:System.out.print ("Five Hundred ");break;
    case 6:System.out.print ("Six Hundred ");break;
    case 7:System.out.print("Seven Hundred ");break;
    case 8:System.out.print ("Eight Hundred ");break;
    case 9:System.out.print ("Nine Hundred ");break;


    }
    }


if ((value>10) && (value<20)){

tens = value/ 10;
ones = value;
elevens = value % 10;


switch (elevens){
case 1:System.out.print("Eleven ");break;
    case 2:System.out.print("Twelve ");break;
    case 3:System.out.print("Thirteen ");break;
    case 4:System.out.print ("Fourteen ");break;
    case 5:System.out.print ("Fifteen ");break;
    case 6:System.out.print ("Sixteen ");break;
    case 7:System.out.print("Seventeen ");break;
    case 8:System.out.print ("Eighteen ");break;
    case 9:System.out.print ("Nineteen ");break;
    }
}
if (value>10000){
System.out.print("INVALID INPUT");
}

else {
tens = value/10;
value = value%10;
ones = value;

switch (tens) {

case 1: System.out.print("Ten ");break;
case 2:System.out.print("Twenty ");break;
case 3:System.out.print("Thirty ");break;

case 4:System.out.print("Fourty ");break;
case 5:System.out.print("Fifty ");break;
case 6:System.out.print("Sixty ");break;
case 7:System.out.print("Seventy ");break;
case 8:System.out.print("Eighty ");break;
case 9: System.out.print("Ninety ");break;
}
switch (ones){

case 1: System.out.print("One ");break;
case 2:System.out.print("Two ");break;
case 3:System.out.print("Three ");break;

case 4:System.out.print("Four ");break;
case 5:System.out.print("Five ");break;
case 6:System.out.print("Six ");break;
case 7:System.out.print("Seven ");break;
case 8:System.out.print("Eight ");break;
case 9:System.out.print("Nine ");break;

                }

}
     System.out.print("\nDo you want to continue (Type y or n) : ");
      ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
      System.out.println();
      System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
      System.out.println("\n\n");
                 
}   

  }