This is my first time writing JAVA, and I'm trying to start off on the right track.
Using my C++ knowledge, I was able to understand the syntax for the ternary operator, but I'm not sure how it should be approached properly in JAVA. I have used Ideone to test this, which include imports
s that apparently aren't even needed for this program, or so it seems.
I'd like a review over anything there is to offer, even if it involves telling me that starting with Ideone is not the best choice for whatever reasons.
import java.util.*;
import java.lang.*;
import java.io.*;
class BeginnerFizzBuzz {
public static void main(String[] args) {
for (int i = 1; i <= 100; ++i) {
System.out.println(
(i % 15 == 0) ? "FizzBuzz" :
(i % 3 == 0) ? "Fizz" :
(i % 5 == 0) ? "Buzz" :
i
);
}
}
}
if
/else
, but I thought that would be redundant as well. But I can now see that this isn't too readable. \$\endgroup\$?:
operator is the conditional operator; a "ternary operator" is any operator that takes three operands (there is only one ternary operator in most programming languages, so people often say "ternary operator" when they mean "conditional operator"). \$\endgroup\$