π¨π» Web Development/Java
[Day10] Java 10 - μ§μ λ³ν
Kim_dev
2022. 9. 1. 20:39
[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 )