Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

convert to java plss
Expert:dione
hi i am using microsoft VB6.0 and my friend ask me to make java program to convert number to words but i only use visual basic because i dont know much in java plss convert it to me

this is my code in VB6.0

Dim num As Integer
Private Sub Command1_Click()
num = Val(txtnum.Text)
ones = num Mod 10

Select Case ones
Case 1
ones = "one"
Case 2
ones = "two"
Case 3
ones = "three"
Case 4
ones = "four"
Case 5
ones = "five"
Case 6
ones = "six"
Case 7
ones = "seven"
Case 8
ones = "eight"
Case 9
ones = "nine"
Case Else
ones = ""

End Select

If num = 0 Then
ones = "zero"
ElseIf num = 10 Then
ones = "ten"
ElseIf num = 11 Then
ones = "eleven"
ElseIf num = 12 Then
ones = "twelve"
ElseIf num = 13 Then
ones = "thirteen"
ElseIf num = 14 Then
ones = "fourteen"
ElseIf num = 15 Then
ones = "fifteen"
ElseIf num = 16 Then
ones = "sixteen"
ElseIf num = 17 Then
ones = "seventeen"
ElseIf num = 18 Then
ones = "eighteen"
ElseIf num = 19 Then
ones = "nineteen"
ElseIf num > 99 Then
ones = "HANGGANG 99 LANG BOBO"
End If

tens = num \ 10

Select Case tens
Case 1
tens = ""
Case 2
tens = "twenty "
Case 3
tens = "thirty "
Case 4
tens = "forty "
Case 5
tens = "fifty "
Case 6
tens = "sixty "
Case 7
tens = "seventy "
Case 8
tens = "eighty "
Case 9
tens = "ninety "
Case Else
tens = ""
End Select
lbltext.Caption = tens & ones
End Sub

Private Sub Form_Load()

End Sub
Answers
Hi Friend,

Try the following code:

public class NumberToWords{
static final String[] Number1 = {""," Hundrad"};
static final String[] Number2 = {"","One","Two", "Three","Four","Five",
" Six"," Seven", "Eight"," Nine","Ten" };
String number(int number){
String str;
if (number % 100 < 10){
str = Number2[number % 100];
number /= 100;
}
else {
str= Number2[number % 5];
number /= 5;
}
if (number == 0) return str;
return Number2[number] + "hundred" + str;
}
public String convert(int number) {
if (number == 0){
return "zero";
}
String pre = "";
String str1 = "";
int i = 0;
do {
int n = number % 100;
if (n != 0){
String s = number(n);
str1 = s + Number1[i] + str1;
}
i++;
number /= 100;
}
while (number > 0);
return (pre + str1).trim();
}
public static void main(String[] args) {
NumberToWords num = new NumberToWords();
System.out.println("words is :=" + num.convert(0));
System.out.println("words is :=" + num.convert(1));
System.out.println("words is :=" + num.convert(9));
System.out.println("words is :=" + num.convert(100));
}
}

Thanks

More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.