Java:
import java.util.TreeMap; public class Main { public static void main(String[] args) { System.out.println("Hello World!"); TreeMap fizzbuzz = new TreeMap(); for (int i = 0; i < 100;) { i++; if (i % 3 == 0) { fizzbuzz.put(i, "Fizz"); } if (i % 5 == 0) { fizzbuzz.put(i, "Buzz"); } if (i % 3 == 0 && i % 5 == 0) { fizzbuzz.put(i, "FizzBuzz"); } } for (Object i: fizzbuzz.keySet()) { System.out.println(i.toString() + " " + fizzbuzz.get(i)); } } }
Kotlin:
fun main(args: Array) { println("Hello World!") val fizzbuzz = mutableMapOf<Int, String>() var i = 0 while (i < 100) { i++ when { i % 3 == 0 -> fizzbuzz[i] = "Fizz" } when { i % 5 == 0 -> fizzbuzz[i] = "Buzz" } when { i % 3 == 0 && i % 5 == 0 -> fizzbuzz[i] = "FizzBuzz" } } fizzbuzz.forEach { i, j -> println("$i, $j") } }