• Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting to Otcal  RSS feed

 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey yo all, Alright I need to make a program that converts to Octal, im using the following "fourmal" to do so:
DivisionQuotientRemainderOctal Number
255 / 8 31 0.875 7
31 / 8 3 0.875 77
3 / 8 0 0.375 377
The decimal number inputted is 255 and the octal number outputted is 377.
How do I use Java to work just off the remainder and then round-down?
Sigh yet again I answer my own question, Ok i should be just using the % to work out the remainder straight from the division, which I then place in a loop this was really hard for me to work out before I sat down and thought about it (and used googles calculator, gooo Google!) Now I just need to know how to append something to a string, any help would be great.
[ April 22, 2004: Message edited by: Peter Shipway ]
 
C. Nimo
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Well - if you want to do it with a String, you're probably looking at
using either a String and appending with a + such as:

or you could be saving the JVM some heap space and go for a StringBuffer:

alrighty?
Nimo.
 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm I get
C:\My Java Programs\Octal.java:22: illegal start of expression
StringBuffer output =...;
^
1 error
Process completed.
When atempting to complie, im trying to set output to nothing in that line
 
Karthikeyan Rajendraprasad
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its
StringBuffer output = new StringBuffer();
and not as specified.
i think Nimo bit lazy to complete it fully (just kidding ) or thought that you can write the constructor properly


any way this is the way to declare StingBuffer
 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks much,
Ah another probelm, now i need to change the way that the number's are added to the string, the current output is 773 instead of 377, i think is called "prepending" any help would be great.
[ April 22, 2004: Message edited by: Peter Shipway ]
 
Mike Fuellbrandt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!