This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 입력된 분(currM)이 0이면 0, 1 ~ 59분이면 1을 갖게 되는 정수이다. | |
// 1시간단위 선불 PC방에서 1분 이상 이용 시 1시간 요금을 추가로 더할 때 등에 사용한다. | |
// 딱 분단위만 따진다. 초단위로 계산하지는 않으니 다른것을 쓰라. | |
int plusHour_becauseofMinutes = (1 - ((60 - currM) / 60)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What you need to input: a month number (1~12) | |
// What you will get: 0 is winter, 1 is spring, 2 is summer, 3 is autumn | |
private static String getSeasonName(int m) { return new String[]{ "Winter", "Spring", "Summer", "Autumn" }[m / 3 % 4]; } | |
// Let's convert each month number to the season string | |
for(int m = 1; m <= 12; m++) System.out.printf("%2d → %s", i, getSeasonName(m) + "\n"); | |
/* | |
[[result]] | |
1 → Winter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A method of returning an array which has reversed order of the original int[] array | |
public static int[] array_reverse_int(int[] arr1) { | |
int[] arr2 = new int[arr1.length]; | |
for(int i = 0; i < arr1.length; i++) arr2[i] = arr1[arr1.length - 1 - i]; | |
return arr2; | |
} | |
// Let's run a sample code | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class c01_ArrayShifter { | |
// Circulate the number in case of overflow | |
private static int chk_overflow(int num, int len) { | |
return num >= len ? (num - len) | |
: num < 0 ? (num + len) | |
: num; | |
} | |
// Circulate an array with the times and the direction what you want |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Object array_reverse(Object[] arr) { | |
for(int i = 0; i < arr.length / 2; i++) { | |
int start = i; | |
int end = arr.length - 1 - i; | |
Object temp = arr[start]; | |
arr[start] = arr[end]; | |
arr[end] = temp; | |
} | |
return arr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What you input: file size (long or its sub type) | |
// What you get: formatted text of a file size. | |
// ex) 23.44 MBytes, 15.20 TBytes, 1,015 Bytes, ... | |
public static String getFileSizeFormatedTxt(long fileSize) { | |
// Unit size infoes | |
Object[][] bytes = { | |
{1099511627776L, "T"}, | |
{1073741824L , "G"}, | |
{1048576L , "M"}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
개요: | |
- KH 과제게시판에 코드를 올리기 위해 커스터마이징한 highlight.js 응용 코드. | |
특징: | |
- Consolas 폰트 사용 | |
- 모바일 레이아웃 지원 (margin/padding 없는 꽉찬 레이아웃 뷰, 가로스크롤, 줄번호 등) | |
- 눈에 더 편하게 보일 수 있도록 일부 엘리먼트 색상 조정 | |
사용법: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
// Returns the string which changed all characters after 'n'th to * | |
public static String strToStar(String s, int n) { | |
return s.substring(0, n) | |
+ new String(new char[s.length() - n]) | |
.replace("\0", "*"); | |
} | |
// Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns the Table String from a String[][] data | |
public static String getTableStr (String[][] data) { | |
// Calculate the maximum lengths of the each columns | |
int[] len = new int[data[0].length]; | |
Arrays.fill(len, 0); | |
for(String[] str: data) { | |
for(int i = 0; i < str.length; i++ ) { | |
String val = str[i]; | |
int stringLen = val == null ? 0 : val.length(); | |
if(stringLen > len[i]) len[i] = stringLen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
코드 단축 및 기능 확장을 위해 만들어본 라이브러리입니다. | |
1. $.pr / $.pn / $.pf : 코드단축용 메소드 | |
// System.out.print → $.pr 코드단축 | |
// System.out.println → $.pn 코드단축 | |
// System.out.printf → $.pf 코드단축 | |
public static void pr (Object o) { System.out.print(o); } |
OlderNewer