I was trying to implement FizzBuzz without modulus operator.
Areas of concern: inner for loop maybe not needed? seq[] array maybe not needed?
class FizzBuzzWithoutModulus{
public static void main(String[] args){
int[] fizzbuzz = new int[101];
int[] buzz = new int[101];
int[] fizz = new int[101];
int[] seq = new int[101];
for(int i=1; i<=100; i++){
seq[i] = i;
}
for(int i=1; i<=100; i++){
for(int j=1; j<seq.length; j++){
if((i/15.0) == seq[j]){
fizzbuzz[i] = i;
}
else if((i/5.0) == seq[j]){
buzz[i] = i;
}
else if((i/3.0) == seq[j]){
fizz[i] = i;
}
}
}
for(int i=0; i<=100; i++){
if(fizzbuzz[i]!=0){
System.out.println(fizzbuzz[i] + " fizzbuzz");
}
else if(buzz[i]!=0){
System.out.println(buzz[i] + " buzz");
}
else if(fizz[i]!=0){
System.out.println(fizz[i] + " fizz");
}
}
}
}
seq[j]should not be a bottleneck. However, the initial filling up ofseqtakes time, which you could save if you replaced the arrayseqwith a methodint seq(int n) {return n;}. \$\endgroup\$