BASIC / CATATAN</>↗Basic19 Sep 2009
The code below demonstrate how to use the while loop statement. The while statement will check if its expression evaluates to true and execute the while statement block. The program below will execute while the countDown value is bigger or equals to zero. package org.kodejava.basic; public class WhileDemo { public static void main(String[] args) { […]
BASIC / CATATAN</>↗Basic19 Sep 2009
The program below demonstrate how to use the switch statement. The switch statement can work with the byte, short, int and char primitive data types and the corresponding wrappers of these data type such as Byte, Short, Integer and Character. It also work with enumerated types, refer to the following example: How do I use […]
BASIC / CATATAN</>↗Basic18 Sep 2009
The if-then-else control flow statement adds a secondary path to the if statement when the expression evaluates to false. When it evaluates to false the else block will be executed. Below is the program that takes input of user test score and evaluates the score to get the corresponding grade. package org.kodejava.basic; import java.io.Console; public […]
BASIC / CATATAN</>↗Basic17 Sep 2009
The if-then is the most basic control flow statement. It will execute the block of statement only if the test expression evaluated equals to true. Let’s see the example below: package org.kodejava.basic; public class IfThenDemo { public static void main(String[] args) { int a = 10; int b = 5; // If the evaluation of […]
BASIC / CATATAN</>↗Basic15 Sep 2009
package org.kodejava.basic; import java.util.HashMap; import java.util.Map; public class NumberOccurrenceInArray { public static void main(String[] args) { int[] numbers = new int[]{1, 8, 3, 4, 3, 2, 5, 7, 3, 1, 4, 5, 6, 4, 3}; Map<Integer, Integer> map = new HashMap<>(); for (int key : numbers) { if (map.containsKey(key)) { int occurrence = map.get(key); occurrence++; […]
BASIC / CATATAN</>↗Basic13 Sep 2009
The double brace initialization {{ … }} is another way for initializing a collection objects in Java. It is offer a simple syntax for initializing a collection object. package org.kodejava.lang; import java.util.ArrayList; import java.util.List; public class DoubleBraceInitialization { public static void main(String[] args) { // Creates a list of colors and add three colors of […]