I had a challenge to print out multiples of 7 (non-negative) to the 50th multiple in the simplest way humanly possible using for loops.
I came up with this (Ignoring the data types)
for(int i = 0; i <= 350; i += 7)
{System.out.println(i);}
The other guy came up with this
for(int i=0;i <=50; i++)
{
System.out.println(7*i);
}
However, I feel the two code snippets could be further optimized. If it actually can please tell. And what are the advantages/disadvantages of one over the other?
System.out.println("0"); System.out.println("7"); System.out.println("14"); .... But you ruled that out in the premise to the challenge. :-P However, "the simplest way humanly possible" can mean many different things; I would it to mean "easiest to maintain" and/or "easiest to understand what's going on by looking at the code," not "fastest."