share this page !

search

Sunday, June 13, 2010

JAVA:Program to Convert integers entered by user to words.


Here are the Mumbai University First Year Engineering sem-2 Computer programing 2 (CP-2) programs.These are tried and tested and work just fine.Njoy!
Please refer this to all your pals on all your social networks..thank you !
The grey color is only for the background it should cause no problems.






--------------------------------------------------------------------------------------------------------------
/*Program to convert integers entered by user into words:
INPUT:1234 Output would be : one two three four*/

import java.io.*;
class Pwords {
public static void main(String args[]) throws Exception
{
DataInputStream ob=new DataInputStream(System.in);
System.out.print("Enter a number: ");
int x = Integer.parseInt(ob.readLine());
int temp;
String str = "";
while (x != 0)
{
temp = x % 10;
switch (temp)
{
case 1: str = "one " + str; break;
case 2: str = "two " + str; break;
case 3: str = "three " + str; break;
case 4: str = "four " + str; break;
case 5: str = "five " + str; break;
case 6: str = "six " + str; break;
case 7: str = "seven " + str; break;
case 8: str = "eight " + str; break;
case 9: str = "nine " + str; break;
case 0: str = "zero " + str; break;
}
x /= 10;
}
System.out.println("Number in words: " + str);
}
}

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Followers

 

Mumbai University Engineering. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com