• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assignment 1.4

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
Here is my code for Assignment 1.4.All comments are welcome.
// Read an int at command line 0-99, and display number spelled out
code
-----------------------------------------------------------------


[This message has been edited by Marilyn deQueiroz (edited December 05, 2000).]
 
Neha Gupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not have any editor other than Notepad.My code is aligned properly in my editor , after posting it is not indented.HELP ???
ANy free editor available..
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use the ubb code tags, your code will indent the way you have typed it.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Neha,
Its good logical code u've used in yr program. I would like to suggest a few change in yr program. You can modify this code in such a way so that it will accept any number and display it in words. e.g. 1012 - one thousand and twelve only
 
Trailboss
Posts: 23780
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neha,
Usually I prefer that you don't post code here. If you post great code, you will be robbing others of an education.
I suggest that you send this assignment on to nitpick@javaranch.com and get proper feedback.
 
Neha Gupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion Kapil,will try doing that.I am just a beginner,Is java HARD to learn.
I will take care Paul not to post code here.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neha,
You didn't use methods - so that's one alteration you've to make. I like your algorithm though.
Shama
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neha,
When i run your program and input a single digit number I get


Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.substring(String.java:1489)
at Say.main(Say.java:3)


Also, when I input 30, 40, 50... I get Thirty-Zero, Forty-Zero, Fifty-Zero...

I'm new to Java, so I don't know if I'm doing something incorrect or not. If so could someone please correct me.
Thanks ~ Jeff

[This message has been edited by Jeff McIlvain (edited January 29, 2001).]
[This message has been edited by Jeff McIlvain (edited January 29, 2001).]
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeff, you are write on both counts. First you get the error becuase you are calling substring(1,2) on something that only has 1 digit, so substring(1,2) looks at the second digit, which there is none.
And for the second error in output, you get that because there is no checks to see if the input is divisble by ten so you don't print the - and zero part.
Bill
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic