Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

From a given string of numeric values, print the individual numbers in words separated by space.

 
Ranch Hand
Posts: 61
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From a given string of numeric values, print the individual numbers in words separated by space.
Input: “2491"

i have written the below prog for the same.


public class notoword {


public static void main(String[] args) {

int n=2346980;
int d;int rev=0;
while(n!=0){
d=n%10;

rev=rev*10+d;

n=n/10;

}
int num=rev;
while(num!=0){
d=num%10;
switch(d){

case 1:System.out.println("one");
break;
case 2:System.out.println("two");
break;
case 3:System.out.println("three");
break;
case 4:System.out.println("four");
break;
case 5:System.out.println("five");
break;
case 6:System.out.println("six");
break;
case 7:System.out.println("seven");
break;
case 8:System.out.println("eight");
break;
case 9:System.out.println("nine");
break;

}
num=num/10;
}

}

}

its not giving output for any string like 2340,9070.
I know I am dividing it by 10 so there is no output for this kind of input.
Please correct my programme as required.And can any one suggest any better solution for this.

Thanks in advance.

 
author
Posts: 23926
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aneek Banerjee wrote:From a given string of numeric values, print the individual numbers in words separated by space.
Input: “2491"

i have written the below prog for the same.



its not giving output for any string like 2340,9070.
I know I am dividing it by 10 so there is no output for this kind of input.
Please correct my programme as required.And can any one suggest any better solution for this.



First, what about zero? Can't zero appear in a number?

Second, is it really a good idea to reverse the number? What is the number 50 in reverse? What is the number 500 in reverse? What is the number 5000000? in reverse? Can you tell the difference?

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic