๐ฅ
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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