Conversation
SChandarana
left a comment
There was a problem hiding this comment.
Couple small things to think about, but a great approach! :D
| public class FizzBuzz { | ||
| public static void main(String[] args) throws Exception { | ||
|
|
||
| ArrayList<String> result = new ArrayList<String>(); |
There was a problem hiding this comment.
Nice this is a pretty good approach! For performance and memory reasons though, you might want to use a "StringBuilder" https://www.geeksforgeeks.org/stringbuilder-class-in-java-with-examples/
Since you're never doing any special array functions (like sorting, splicing etc)
| if (result.size() == 0) { | ||
| result.add(String.valueOf(i)); | ||
| } |
There was a problem hiding this comment.
This is also a scenario in which I can introduce my favourite programming operator called the "ternary operator" https://www.w3schools.com/java/java_conditions_shorthand.asp
its perfect for when you want to do "if then else ". In this case it could be within the System.out.println you can check the length of the array/stringBuilder and return i if its 0, or the join if not
Basic code for a fizzbuzz program using Java.
Playing around with Java's ArrayLists methods and uses.