Skip to content

Instantly share code, notes, and snippets.

Avatar

Rio Swarawan Putra swarawan

View GitHub Profile
View Latihan Decision - Loop
Buat sistem lift
- ada 20 lantai
- posisi pemain ada di lantai `x`
- pemain ingin ke lantai `y`
Soal:
gambarkan alur lift tersebut.
Contoh:
posisi pemain = 5
@swarawan
swarawan / Sistem Parkir
Last active Mar 9, 2018
Belajar menggunakan kondisi (decision) dan perulangan (loop)
View Sistem Parkir
total roda <= 2 -> lahan parkir sebelah kiri
total roda > 2 <=4 -> lahan parkir sebelah kanan
total roda > 4 -> basement
check here -> https://github.com/swarawan/batch-6-java-basic.git
View gist:e2f29290f695d27d5a5b20ed849147a8
/**
* Return string formatted with dot separator and prepended with currency
* symbol (IDR). By default will return Rp 0.
*
* @param defaultOutput Default string to return (with currency prefix) when error happen.
*/
@NonNull
public static final String formatCurrency(@Nullable BigDecimal input, @NonNull String defaultOutput) {
if (input == null)
return defaultOutput;
@swarawan
swarawan / Get Duration
Created Sep 14, 2017
Get duration depend on inserted Date.
View Get Duration
public static String getDurationDate(Date date) {
Date today = new Date();
long diff = today.getTime() - date.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000) % 30;
long diffWeeks = diff / (30 * 24 * 60 * 60 * 1000) / 4;
long diffMonth = diff / (30 * 24 * 60 * 60 * 1000);
@swarawan
swarawan / DateUtils.java
Created Jun 19, 2017
Pretty date format to get duration.
View DateUtils.java
public class DateUtils {
public static String getDurationDate(Date date) {
Date today = new Date();
long diff = today.getTime() - date.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000) % 30;
long diffWeeks = diff / (30 * 24 * 60 * 60 * 1000) / 4;