X Tutup
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Ron McLeod
Saloon Keepers:
  • Tim Holloway
Bartenders:

Reverse Java Code

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again guys.
So I've got a code which performs a basic mathematical function to produce a final number. I thought it was working fine, until posting this, it seems evident there are some issues.

The next task I've got is to reverse the process. I.E I've got a list of results I need to produce by working in reverse order. I need to figure out the original number.

This should be easy, I've done algebra in school, and could do most of it on paper. Although the "While" line is really putting me off, and I don't know how to approach it.

Can someone give me some advice, or provide some insight to something I may be overlooking?

I need to produce the following integers/doubles (12.0, 15.75, 19.5, 23.25, 27.0)

Regards,

Cory








 
Marshal
Posts: 82158
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume the bit missed out of line 7 is intentional; you should always post the real code, otherwise you might introduce other errors which confuse us when we are answering.
In order to understand the while loop, try reading line 9 out loud.

So we can see whether your function is working, please tell us what the algorithm is. You are not getting integers or doubles there, only doubles. A number ending nnn.0 is not an integer, even if its fractional part is zero.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code can be used to reverse a number.
 
Marshal
Posts: 6298
507
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Amelia, welcome to the Ranch!

When posting code it's recommended to UseCodeTags to help make it readable. I've added them for you this time, see how much better it looks.

Now, back to the topic in hand. I don't think the program you have posted is in any way related to the original question in this thread. Perhaps you misread the question?
 
Cory Marcus
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys.
Think I've figured out my issue.
Thanks for your help!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cory Marcus wrote:Hey guys.
Think I've figured out my issue.
Thanks for your help!



Hi Cory,
Here is an easier way to generate those numbers:




Now, your method posted above has some errors:
- it produces just one number, because of the return statements
- if the return statements were to be removed, it would produce more numbers than the list in your initial post
I have refactored your method a bit, and removed the return statements:

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic
X Tutup