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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vijayababu
Number Convert
1 Answer(s)      6 years and 6 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
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 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
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
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
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
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  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
prime number
prime number  check prime number using if statement   Java Check Prime Number
 

 

 

DMCA.com