[Day10] Java 10 [8/22]
1. String ํด๋์ค ํจ์(๋ฉ์๋)
charAt(index)
equals()
split(regex)
matches(regex)
substring()
trim()
valueOf()
format()
join()
2. 10์ง์ 2์ง์ ์ ํ
// [๋ฌธ์ ] 10์ง์ ์ ์๋ฅผ ์
๋ ฅ๋ฐ์์
// 2๋ฐ์ดํธ 2์ง์ํํ๋ก ์ถ๋ ฅํ์ธ์.
// ์) 10
// 0000 0000 0000 1010
Scanner scanner = new Scanner(System.in);
System.out.print("> 10์ง์ ์ ์ ์
๋ ฅ ? ");
int n = scanner.nextInt();
int [] binaryArray = new int[16];
int index = binaryArray.length - 1;
// 4:10 ํ์ด ์์
// n = 10
int share = n, rest ;
/*
share = share /2; // 5
rest = share % 2; // 0
binaryArray[ index ] = rest;
index--;
share = share /2; // 2
rest = share % 2; // 1
binaryArray[ index ] = rest;
index--;
share = share /2; // 1
rest = share % 2; // 0
binaryArray[ index ] = rest;
index--;
:
:
*/
// ์ค๋จ์ (break point) F11 ๋๋ฒ๊น
~
while( share != 0 ) {
rest = share % 2;
share = share /2;
binaryArray[ index-- ] = rest;
}
// int [] ๋ฐฐ์ด์ ์ด๊ธฐํ ํ์ง ์์ผ๋ฉด int์ ๊ธฐ๋ณธ๊ฐ์ธ 0์ผ๋ก ์ด๊ธฐํ ๋์ด์ ธ ์๋ค...( ์๊ธฐ )
// [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
System.out.println( Arrays.toString( binaryArray ) );
// 00000000000010
String result = Arrays.toString( binaryArray ) ;
result = result.replaceAll(",\\s", "");
System.out.println( result.substring(1, result.length()-1) );
String binaryN = Integer.toBinaryString( n )
์ต๊ทผ๋๊ธ