Re: java code
lipska the kat wrote:
Well. Now that everyone has had the obligatory attempt at being a
smartarse and, hopefully, you have had time to figure this out for
yourself, try this. There are some possible 'optimizations' depending on
you view regarding 'unnecessary' variables and hard-coded magic numbers.
I'm sure some of the smartarses will offer their invaluable advice in
this area.
Absolutely.
public class AntiSmartArseClass {
It is pointless to put 'Class' into a class name, as we already now that it's a class from
the (you guessed it) 'class' keyword.
More to the point, thinking in terms of classes is a less powerful mode than
thinking in terms of types. Names should be semantic, and not reflective of
implementation.
public static void main(String[] args) {
int increment = 11;
This would be better as a constant.
int iterations = 8;
int outerindex = 1;
int innerindex= 0;
Looks like you're reinventing the 'for' loop here.
while(outerindex <= iterations){
Yep.
System.out.printf("%d", outerindex * increment);
innerindex = (outerindex * increment) % 10;
And the nested 'for' loop.
while(innerindex > 1){
Which proves that you are all macho and everything, sure, but
the problem is that these variables have too wide a scope. Use
of the 'for' loop brings you proper scoping for free.
System.out.printf("%d", --innerindex);
}
outerindex++;
You really should follow the Java Naming Conventions, which call for camel
case on these variables.
System.out.println();
}
}
}
You're welcome.
--
Lew