Thursday, November 18, 2010

program for convert number to word in java

class no_to_word
{
public static  void notoword(int n)
{
String once[]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty",};
String tens[]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
if(!(n<=1)&&(n>=100))
System.out.println("invalid");
else
{
if(n<20)
System.out.println(once[n]);
else
{
int i=n/10;
n=n%10;
if(n==0)
System.out.print(tens[i-2]);
else
System.out.println(tens[i-2]+" "+once[n]);
    }
}
    }
}

2 comments:

Anonymous said...

hi

iam begineer to java programming...

kindly give me solution to the error..

Error: Main method not found in class no_to_word.no_to_wordJava, please define the main method as:
public static void main(String[] args)

siva said...

You have to add main method to above program and call that method on main method.