File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Cattle Drive and the fly likes Java 4b technique, pt 2. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Java 4b technique, pt 2." Watch "Java 4b technique, pt 2." New topic

Java 4b technique, pt 2.

Paul Ralph
Ranch Hand

Joined: Aug 10, 2000
Posts: 312
I don't know how to ask this without posting my code. Cue the lightning bolts...

> int nameIndex = 1; //cannot be set to 0 or upcoming loop will never be entered
> long tempNumber = 0;
> while ( nameIndex > 0)
> {
> tempNumber = number ;
> nameIndex = 0;
So you set it to 1 and immediately reset it to zero. Why not use
while ( nameIndex >= 0 )
in the first place?

Because then the loop will never exit. I want it exit when
( nameIndex == 0) at the end of the loop. I could avoid the funky immediate variable change by using
} while ( nameIndex > 0)
to make the loop is entered at least once, but this is strictly forbidden by the style guide.

> // seperate the first three digits and find correct index for modifier
> while ( tempNumber > 1000)
This loop is run through four times. That doesn't seem like very many. Sometimes when a loop
does this few iterations, it turns
out to be easier to just hard code the four instances.

Actually, if the number is in the billion range it will be used 6 times (3+2+1), 3 for million, once for the thousand range, and none at all if the number is less than a thousand.
Is there a way to
a) Get the first three digits
b) Find the index of the array for the modifier (billion, million, thousand)
without using a loop?
I get the message: Don't use a loop!!! How do I do that without having to completely rewrite my code?
Paul R
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
dear Ralph
I cannot help you much as i am also trying to make my attempt to 4b. But i hope you will get your reply in the following thread:

Paul Ralph
Ranch Hand

Joined: Aug 10, 2000
Posts: 312
I think it gave me what I needed. At the very least I have another version that's on its way. (Note: I'd read it before, but sometimes it takes more than one reading)
int numberOfLoops = 0; //
int numberOfMethods = 3; // main counts as 1
Shine the light in my face long enough and I'll eventually see it. Now I understand why others have said that BASIC and FORTRAN programming has haunted them. How right they were....
Paul R

[This message has been edited by Paul Ralph (edited May 17, 2001).]
I agree. Here's the link:
subject: Java 4b technique, pt 2.
It's not a secret anymore!