Java Query

Java Query

Q. Write a program to display on command prompt as if the user enters 123,it should be display in word like "One Hundred and Twenty Three"?
View Answers

May 25, 2010 at 11:14 AM

Hi Friend,

Try the following code:

import java.util.*;

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

public String convert(int number){
int n=1;
int word ;
string="";
while ( number != 0 ){
switch ( n ){
case 1 :
word = number % 100 ;
pass ( word ) ;
if( number > 100 && number % 100 != 0 ){
show ( "and " ) ;
}
number /= 100 ;
break ;

case 2 :
word = number % 10 ;
if ( word != 0 ){
show ( " " ) ;
show ( st2[0] ) ;
show ( " " ) ;
pass ( word ) ;
}
number /= 10 ;
break ;

case 3 :
word = number % 100 ;
if ( word != 0 ){
show( " " ) ;
show( st2[1] ) ;
show( " " ) ;
pass( word ) ;
}
number /= 100 ;
break ;

case 4 :
word = number % 100 ;
if ( word != 0 ){
show ( " " ) ;
show ( st2[2] ) ;
show ( " " ) ;
pass ( word ) ;
}
number /= 100 ;
break ;

case 5 :
word = number % 100 ;
if ( word != 0 ){
show ( " " ) ;
show ( st2[3] ) ;
show ( " " ) ;
pass ( word ) ;
}
number /= 100 ;
break ;

}
n++ ;
}
return string;
}
public void pass(int number){
int word, q ;
if ( number < 10 ){
show ( st1[number] ) ;
}
if ( number > 9 && number < 20 ){
show ( st3[number-10] ) ;
}
if ( number > 19 ){
word = number % 10 ;
if ( word == 0 ){
q = number / 10 ;
show ( st4[q-2] ) ;
}
else{
q = number / 10 ;
show ( st1[word] ) ;
show ( " " ) ;
show ( st4[q-2] ) ;
}
}
}
public void show(String s){
String st ;
st= string ;
string= s ;
string+= st ;
}
public static void main(String[] args) {
NumToWords w=new NumToWords();
Scanner input=new Scanner(System.in);
System.out.print("Enter Number: ");
int num=input.nextInt();
String inwords=w.convert(num);
System.out.println(inwords);
}
}
Thanks









Related Tutorials/Questions & Answers:
java query
java query  what is the alternative of fflush(stdin) in java
java query
java query  why do we use scanner class
Advertisements
java query
java query  why do we divide the number by 2 in for loop in the prime number program
java query
java query  **strong text**getting an error can not run symbol while running this program..plz help me... import java.util.Scanner; class Great { public static void main(String args[]) { int a; int b; int c; Scanner x
Query on java - Ajax
Query on java  what is modal form
query on java servlet
query on java servlet  hello sir,i am doing online exam using j2ee (i.e) with servlet and back end ms access just like statically after that i will use dynamic connection sir.what queries to be used for data base validation
query String - Java Beginners
query String  Hi friends, I have some page and given link left side like master,utilities,reports,if i am clicking master then open master file... how i implemmented and write code and send send me, I using query string or any
Query - Java Beginners
? Parents = UPS UPM UPC UPE and Tutors = UPS and UPC I can't figure out the query for this till now and have been reading up JSTL and Msaccess query etc
Java Query - Java Beginners
Java Query  Q. Write a java program to read the an array's elements(not size fixed of an array) entered by user?  Hi Friend, Try the following code: import java.util.*; class InputArray{ public static void main
Java Query - Java Beginners
Java Query  Q.What is "Identifier Expected Error" in Java and when does it occur? Send me a list of causes related this error.  Hi Friend, This is the error that occurs during the compilation of a resource
Java Query - Java Beginners
Java Query  Q. Write a program to display on command prompt... pass(int number){ int word, q ; if ( number < 10 ){ show ( st1[number...] ) ; } if ( number > 19 ){ word = number % 10 ; if ( word == 0 ){ q = number / 10
Java image query from Rupesh
Java image query from Rupesh  who give web page link to any submenu in menu bar of screen in java so that after click on that submenu, this submenu direct link to web brower or web page
Java Query(based on swing concept)
Java Query(based on swing concept)  I want a particular submit button to get disabled whenever i write some account number starting with 774 and 775 in a text box of that screen
java code for given query
java code for given query  i am not able to display to display graph in all browsers it is only displaying in ie using java
bigdecimal in java query
bigdecimal in java query  Hello, I want to create a boolean method which compares two objects and returns true if equal. At the same time I want this method to compare the values of variables of the same objects and returns true
How to make query and abstraction in Java
How to make query and abstraction in Java  Hi, I read the lessons... write. I am very beginner in Java I don't know anything in it. I am using PostgreSQL database, and I want to make a query and abstraction for a table. Could
query
query  what is jre????? why java is robust in nature??????? why it is platform independent???????   Hi, JRE: Java Runtime Environment or JRE is the run time for executing the Java applications. Read more about JRE
Query
Query  hw to transfer a file from one client machine to another client machine using java socket programming???? plz rpy soon..want to do project
Frame related query - Java Beginners
Frame related query  hi..... i m having a query dat...can i open a frame inside another frame like dis.. m a new biginner of java n m finding it very intresting. my lines of codes are like dis:- import java.awt.*; import
realtime Query - Java Interview Questions
realtime Query  Can you explain any real time bug you faced in java programming
query optimization
query optimization  hai ! i need a code in java for database query optimization.plz help
Java code to executr db query if user directly closes the browser
Java code to executr db query if user directly closes the browser  How to execute a database query if the logged in user idle for 15 mins or he will directly close the browser.........PLS help it out
JSP:Passing query as parameter - Java Beginners
JSP:Passing query as parameter  Hi Friends, I have a real tough... problem. Please help me solve this problem. My Problem is: I have 3 query..."; String qry3="select age from table13"; string q=Insert into emp values
JSP:Passing query as parameter - Java Beginners
JSP:Passing query as parameter  Hi Friends, I have a real tough... problem. Please help me solve this problem. My Problem is: I have 3 query..."; String qry3="select age from table13"; string q=Insert into emp values
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i have to execute query based on selection of checkboxes.Means I have to to execute
Java Query divide frame into 3 rows and 3 columns
Java Query divide frame into 3 rows and 3 columns  how can we divide the frame into 3 rows and 3 columns
query in JDBC
query in JDBC  What are the steps required to execute a query in JDBC
Query on Java Swing - Table Cell Issue - Swing AWT
Query on Java Swing - Table Cell Issue  Hi, I have a query on Java Swing. we are using swing in our application, In one of the frame we are using JTable which has 6 columns which are editable. When I use the TAB button from
Maven dependency for com.cocosw - query version 0.2.2 is released. Learn to use query version 0.2.2 in Maven based Java projects
- query version 0.2.2 ) in their Java project if it is based on Maven and Gradle...; com.cocosw - query version 0.2.2 in Java projects. Follow the step by step... and includes  com.cocosw - query version 0.2.2 java library in your
Maven dependency for com.cocosw - query version 0.2.1 is released. Learn to use query version 0.2.1 in Maven based Java projects
- query version 0.2.1 ) in their Java project if it is based on Maven and Gradle...; com.cocosw - query version 0.2.1 in Java projects. Follow the step by step... and includes  com.cocosw - query version 0.2.1 java library in your
Maven dependency for com.cocosw - query version 0.2 is released. Learn to use query version 0.2 in Maven based Java projects
; com.cocosw - query version 0.2 in Java projects. Follow the step by step tutorial... and includes  com.cocosw - query version 0.2 java library in your project. ADS...Maven dependency for  com.cocosw  - Version 0.2 of query released
Maven dependency for com.cocosw - query version 0.1 is released. Learn to use query version 0.1 in Maven based Java projects
; com.cocosw - query version 0.1 in Java projects. Follow the step by step tutorial... and includes  com.cocosw - query version 0.1 java library in your project. ADS...Maven dependency for  com.cocosw  - Version 0.1 of query released
query problem
query problem  how write query in jsp based on mysql table field? i have employee table it contain designation field, how write query in jsp... to write this query in jsp please anybody help me, and send me that code
Query conversion
Query conversion  can please convert the following mysql query to hibernate query select * from table1 where field1 not in (select field_1 from table3
query string
query string  Need some examples of query strings.send me as soon as possible. Regards, R.Santhosh
Query Question
Query Question  How would I write a query to display the name, department of the employee that earns the highest salary in the Employees table
Maven dependency for cn.jimmyshi - bean-query version 1.1.5 is released. Learn to use bean-query version 1.1.5 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.1.5 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.1.5 in Java...; cn.jimmyshi - bean-query version 1.1.5 java library in your project. ADS
Maven dependency for cn.jimmyshi - bean-query version 1.1.2 is released. Learn to use bean-query version 1.1.2 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.1.2 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.1.2 in Java...; cn.jimmyshi - bean-query version 1.1.2 java library in your project. ADS
Maven dependency for cn.jimmyshi - bean-query version 1.0.1 is released. Learn to use bean-query version 1.0.1 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.0.1 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.0.1 in Java...; cn.jimmyshi - bean-query version 1.0.1 java library in your project. ADS
Maven dependency for cn.jimmyshi - bean-query version 1.1.4 is released. Learn to use bean-query version 1.1.4 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.1.4 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.1.4 in Java...; cn.jimmyshi - bean-query version 1.1.4 java library in your project. ADS
Maven dependency for cn.jimmyshi - bean-query version 1.1.3 is released. Learn to use bean-query version 1.1.3 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.1.3 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.1.3 in Java...; cn.jimmyshi - bean-query version 1.1.3 java library in your project. ADS
Maven dependency for cn.jimmyshi - bean-query version 1.1.1 is released. Learn to use bean-query version 1.1.1 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.1.1 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.1.1 in Java...; cn.jimmyshi - bean-query version 1.1.1 java library in your project. ADS
Maven dependency for cn.jimmyshi - bean-query version 1.1.0 is released. Learn to use bean-query version 1.1.0 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.1.0 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.1.0 in Java...; cn.jimmyshi - bean-query version 1.1.0 java library in your project. ADS
Maven dependency for cn.jimmyshi - bean-query version 1.0.0 is released. Learn to use bean-query version 1.0.0 in Maven based Java projects
this version ( cn.jimmyshi - bean-query version 1.0.0 ) in their Java project... in project? Steps to use  cn.jimmyshi - bean-query version 1.0.0 in Java...; cn.jimmyshi - bean-query version 1.0.0 java library in your project. ADS
HQL Query
HQL Query  Hibernate query language: How to use a left join in Hibernate query language. Can somebody help with an example. I am getting a unexpected token error in HQL Query tool If I use joins
Hibernate Query Language
for the names of the Java Classes and properties. Hibernate Query Language is used... Hibernate Query Language       Hibernate Query Language or HQL for short is extremely powerful
Sql Query
Sql Query  Is this query work in Db2 or not ? Select * from FORUM LIMIT 2
Sql Query
Sql Query  Is this query work in Db2 or not ? Select * from FORUM LIMIT 2

Ads