0% found this document useful (0 votes)
4 views1 page

Program Number

This Java program converts a number between 1 and 999 into its English word representation. It uses arrays to store the words for ones, teens, and tens, and processes the input number to construct the corresponding word format. The main method prompts the user for input, creates an instance of the NUMBER class, and displays the result in words.

Uploaded by

gangulyayush9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Program Number

This Java program converts a number between 1 and 999 into its English word representation. It uses arrays to store the words for ones, teens, and tens, and processes the input number to construct the corresponding word format. The main method prompts the user for input, creates an instance of the NUMBER class, and displays the result in words.

Uploaded by

gangulyayush9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;
class NUMBER
{
String ones[]={"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
String
tens1[]={"TEN","ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN"};
String tens2[]={"TWENTY","THIRTY","FORTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINETY"};
int copy,reminder,count=0;String word;
int n;
NUMBER(int num)
{
word="";
n=num;
copy=n;
}
void convert()
{
if(n<1000 && n>0)
{
while(n>0)
{
reminder=n%10;
++count;
if(count==1)
{
if(n/100<20 && n/100>=10)
word=tens1[reminder-1]+" "+word;
if(reminder!=0)
word=ones[reminder-1]+" "+word;
}
if(count==2)
{
if(reminder==1)
word=word;
if(reminder!=0)
word=tens2[reminder-2]+" "+word;
}
if(count==3)
word=ones[reminder-1]+" HUNDRED "+word;
n=n/10;
}
}
else
[Link]("Wrong output");
}
void display()
{
[Link]("Number:"+copy);
[Link]("In words:"+word);
}
public static void main()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter a number between range 0 to 1000");
int n1=[Link]();
NUMBER ob=new NUMBER(n1);
[Link]();
[Link]();
}
}

You might also like