Tiya Khambadkone wrote:I still feel, it needs to be refined especially at step 3. Any thoughts?
Well, a couple leap out at me:
1. You need to convert this number this number to a
String. Specifically, you need to convert numbers in the range 100-775 to one containing two letters. So how about writing a method that takes a number and returns a String? viz:
that way, you remove all that code from your
if block;
and (probably even more importantly) from
main().
It's a good rule to learn: whenever you have a major piece of logic - particularly if you can give it a
name - put it in a method. You'll find that it makes your program much easier to read and follow.
Now your
main() code might look something like:
Alternatively (and possibly even better), you could write another method that includes the
entire conversion process and calls
convertToLetters() itself (ie, have
two methods). Then your
main() code becomes something like:
String numberString = convert(number);
And what could be easier to read than that?
PS: Note that the conversion method is
private. It's only for OUR internal use, not everybody's.
2. Lines 9-12 are redundant. You can just write:
int q = number/26;
int r = number%26;
HIH
Winston
PS: I broke up some of those enormous lines of yours. Please
DontWriteLongLines. Thanks.