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:

Java program to reverse a number

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote this Java program to reverse a number using a while loop. Is this the correct approach, or is there a more efficient way to do this in Java?

 
Sheriff
Posts: 9083
670
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like in your other thread. Please put some effort in testing your own code, that's your responsibility to test to your best abilities.

Please show us what inputs you have tried and what outputs you got. If that won't answer, then we can discuss the outcomes in more detail.
 
Marshal
Posts: 82157
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Make sure to test your program with negative numbers, unless you are specifically restricting its domain to natural numbers.
You aren't writing object‑oriented code, but procedural code. I suggest you change to a functional style:-You can now use that method from elsewhere, preferably in a second class.

Please always use the code button. I shall use it on your code and you can see how much better it will look
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic
X Tutup