Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


vijayababu
Number Convert
1 Answer(s)      6 years and 3 months ago
Posted in : Java Beginners



Advertisement
View Answers

May 22, 2008 at 7:40 PM


Hi

import java.io.*;

public class NumberToWord {
String string;
String a[]={"","one","two","three","four","five","six","seven","eight","nine",};
String b[]={"hundred","thousand","lakh","crore"};
String c[]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ninteen",
};
String d[]={"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninty"};

public String convertNumber(int count){
int in=1;
int num ;
string="";
while (count != 0){
switch (in){
case 1:
num = count % 100;
passString(num);
if( count > 100 && count % 100 != 0 ){
displayOutput("and ") ;
}
count /= 100 ;
break ;
case 2:
num = count % 10 ;
if ( num != 0 ){
displayOutput(" ") ;
displayOutput(b[0]);
displayOutput(" ");
passString(num);
}
count /= 10 ;
break ;

case 3 :
num = count % 100 ;
if ( num != 0 ){
displayOutput(" ") ;
displayOutput(b[1]) ;
displayOutput(" ") ;
passString(num) ;
}
count /= 100 ;
break ;
case 4 :
num = count % 100 ;
if (num != 0){
displayOutput(" ");
displayOutput(b[2]);
displayOutput(" ");
passString(num) ;
}
count /= 100 ;
break ;

case 5 :
num = count % 100 ;
if (num != 0){
displayOutput(" ") ;
displayOutput(b[3]) ;
displayOutput(" ") ;
passString(num) ;
}
count /= 100 ;
break ;

}
in++ ;
}
return string;
}

public void passString(int number){
int num, q ;
if (number < 10 ){
displayOutput(a[number]) ;
}
if (number > 9 && number < 20 ){
displayOutput(c[number-10]) ;
}
if ( number > 19 ){
num = number % 10 ;
if ( num == 0 ){
q = number / 10 ;
displayOutput (d[q-2]) ;
}
else{
q = number / 10 ;
displayOutput(a[num]);
displayOutput(" ") ;
displayOutput(d[q-2]);
}
}
}

public void displayOutput(String s){
String t ;
t= string ;
string= s ;
string+= t ;
}

public static void main(String args[]) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Display massage number to Text!");
NumberToWord num=new NumberToWord();
System.out.println("Number to word: "+num.convertNumber(10)+".");
System.out.println("Number to word :"+num.convertNumber(15)+".");
System.out.println("Number to word :"+num.convertNumber(50)+".");
System.out.println("Number to word :"+num.convertNumber(99)+".");
System.out.println("Number to word :"+num.convertNumber(150)+".");
System.out.println("Number to word :"+num.convertNumber(234)+".");
System.out.println("Number to word :"+num.convertNumber(250)+".");
}
}


Related Tutorials/Questions & Answers:
Number Convert - Java Beginners
passString(int number){ int num, q ; if (number < 10 ){ displayOutput(a[number...]) ; } if ( number > 19 ){ num = number % 10 ; if ( num == 0 ){ q = number / 10 ; displayOutput (d[q-2]) ; } else{ q = number / 10 ; displayOutput(a[num
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
Advertisements
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
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
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
PHP convert week number to days or month - PHP
PHP convert week number to days or month  Small, simple and easy code that can do following task: 1.Convert Week Numbers to Month 2.Convert Week to Date Generally, we use the date time object in PHP to convert the date
jQuery Convert string to number
jQuery Convert string to number In this tutorial , we will discuss about how to convert string (enter into input box) into number. In this example... it from input and also need to convert into number. We can do this by following
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
Java Convert Number to Words
Java Convert Number to Words In this section, you will learn how to convert...", "ninty" }; public String convert(int number) { int n = 1; int word...; } public void pass(int number) { int word, q; if (number < 10) { show(st1
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
Convert Number Format
Convert Number Format   ... about converting a String value in the page to the Number object. When converting,  minimum and maximum number of digits in the integer
Convert Decimal into Binary
Convert Decimal into Binary        In this section, you will learn to convert decimal number...; a decimal number into a binary number.  Description of program: This program
Convert Decimal to Integer
Convert Decimal to Integer       In this section, you will learn to convert  a decimal number into an integer. The java.lang package provides the functionality to convert
Convert Decimal to Octal
Convert Decimal to Octal       In this section, you will learn to convert decimal number into octal...) with base  10. The octal number has 8 digits (as: 0,1,2,3,4,5,6,7) with base 8
Convert Binary to Decimal
Convert Binary to Decimal      ... number  into a decimal number. The java.lang package provides the facility to convert the integer data into the binary to decimal.  Code Description
Convert Hexa To Char
; In this example, you will learn how to convert hexadecimal to char number. The following program provides you convert it into the hexa to char number. Code... string. This program takes a hexadecimal number at console and convert
Convert Decimal To Fraction
Convert Decimal To Fraction       In this example, you will learn how to convert decimal number... will also learn how to convert a decimal number into fraction with the help
Convert Octal to Decimal
Convert Octal to Decimal       In this section, you will learn to convert an octal number to decimal. The following program helps you converts number octal to decimal. 
Convert Byte to Hexadecimal
Convert Byte to Hexadecimal       In this section, We are going to convert a byte value into a hexadecimal number. The package java.lang provides the functionality
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     
Convert Decimal To Character
. In this example, we are going to convert decimal number to its corresponding character... Convert Decimal To Character     ... to convert the decimal into the corresponding character.. Here is the code
Convert a String to Hexa
Convert a String to Hexa       In the example given below, you will learn how to convert String to hexadecimal  number. This example takes a user input string and convert
convert to decimal
convert to decimal  f42a4 convert to decimal by using java
Number conversion in JavaScript
Number conversion in JavaScript  How do you convert numbers between different bases in JavaScript
buzz number
buzz number  buzz number
convert to GUI
convert to GUI  import java.util.Scanner; public class Exam { public static void main (String args[]) { int numberStudent, mark, markAplus = 0... Scanner(System.in); System.out.print("Please enter number of students in class
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array
the number of parameters
the number of parameters  How do I find out the number of parameters passed into function
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
prime number
prime number  could u pls help me out in finding whether a number is a prime number or not?   import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
prime number
prime number  To check a number entered by user is prime or not?   Java check prime number import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
Armstrong number
Armstrong number  I want java program for Armstrong number
prime number
prime number  To check a number entered by user is prime
prime number
prime number  HI!I want a java program that accepts a number from user and displays whether it is a prime number or not using BufferedReader
prime number
prime number  to check wethere given number is prime or not?  ... { static boolean isPrime(int number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1
Convert - Applet
Convert   Hello dear colleques I would like to ask about some converting program currently i am doing converting program my graduation report. I came from mongolia and I live in korea now. therefore my supevisor gave
Count number of "*"
Count number of "*"  I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea? import...++; } } System.out.println("The number of vowels in the given sentence
Number Pyramid
Number Pyramid  Hi Everyone, Can someone help me write the code for the following number pyramid: print... 0 0 0 0 4 ... "); There is 5 spaces in between each number
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
number pyramid
number pyramid   how to get the code for the following : 1 123 12345 1234567   class Pyramid{ public static void main(String args[]){ for(int i=1;i<=7
random number
random number   Please How do I generate a program that gives me random integer from 115 to 250? Using java.util.random. Thank you very much!   Hi Friend, Try the following code: import java.util.*; public final
number sorting
number sorting  program to sort a list of numbers in descending order where the inputs are entered from keyboard in runtime   Hi Friend, Try the following code: import java.util.*; class SortListInDescendingOrder
convert excel into pdf
convert excel into pdf  How to convert excel into pdf files
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
Convert the code to GUI
Is it possible to convert a code into GUI  Is it possible to convert a code into GUI
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
Advertisements
 

 

 

DMCA.com