일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- 코딩테스트
- Filter
- 다시정리하기
- filternot
- 코틀린
- 다시 정리해야함
- 다시봐
- 알고리즘 인증_2주차
- 알고리즘 인증_1주차
- iPortfolio
- 알고리즘 인증
- 취준기록
- array랑 list
- recyclerview
- foldindexed
- Today
- Total
목록Coding [공부기록] 📚 (15)
Moments of growth
return - 함수를 종료하고 값을 반환하는 역할 break - 반복문 내의 구문이 실행되는 중간에 즉시 반복문을 종료하고 다음 구문으로 넘어가는 역할 continue - 다음 반복조건으로 즉시 넘어가는 역할 코틀린의 특징 다중반복문에서 break나 continue가 적용되는 반복문을 label을 통해 지정할 수 있는 기능 loop@for(i in 1..10){ for(j in 1..10){ if(i==1 && j==2) break@loop println("i : $i, j : $j") } } 논리 연산자 1. && 2. || 3. ! https://www.youtube.com/watch?v=gMuxnwDYKhc *유튜브 영상을 보고 혼자 정리한 것입니다.
조건형 반복문 - 조건이 참인 경우 반복을 유지 범위형 반복문 - 반복 범위를 정해 반복을 수행 조건형 반복문 1. while 2. do while 범위형 반복문 1. for for(i in 0..9){ print(i) } //0123456789 for(i in 0..9 step 3){ print(i) } //0369 for(i in 9 downTo 0){ print(i) } //9876543210 for(i in 9 downTo 0 step 3){ print(i) } //9630 for(i in 'a'..'e'){ print(i) } //abcde https://www.youtube.com/watch?v=96rFgaDR5xM *유튜브 영상을 보고 혼자 정리한 것입니다.
비교연산자 1. 부등호 2. 등호 (==) 3. is 연산자 a is Int //좌측 변수가 우측 자료형에 호환되는지 여부를 체크하고 형변환까지 한번에 진행시켜줌 4. !is 연산자 다중조건문 when (switch문을 더 편하게 바꾼 기능) - 하나의 변수를 여러개의 값과 비교 가능 1) when을 조건에 맞는 동작을 하는 조건문으로서 이용할 경우 fun doWhen(a: Any){ //Any는 어떤 자료형이든 상관없이 호환되는 코틀린의 최상위 자료형 when(a) { 1-> println("1") "Hello" -> println("안녕") is Long -> println("Long 타입입니다.") !is String -> println("String 타입이 아닙니다.") else -> printl..
타입추론 - 변수나 함수들을 선언할 때나 연산을 할 때 자료형을 코드에 명시하지 않아도 코틀린이 자동으로 자료형을 추론해주는 기능 기본 자료형들도 선언시 값을 할당만 해주면 대부분 자료형을 명시할 필요가 없음 - 일반 정수형 리터럴을 할당하면 Int - L이 붙은 정수형 리터럴은 Long - 일반 실수형 리터럴은 Double - f가 붙은 실수형 리터럴은 Float - 16진수와 2진수는 Int - Boolean과 Char 추론 가능 함수 - 특정한 동작을 하거나 원하는 결과값을 연산하는데 사용 fun add(a:Int, b:Int, c:Int): Int { return a+b+c } -> 단일 표현식 함수로 간단하게 fun add(a: Int, b: Int, c: Int) = a+b+c 반환형의 타입추..
형 변환- 하나의 변수에 지정된 자료형을 호환되는 다른 자료형으로 변경하는 기능 기본 자료형은 자료형 간의 형변환을 지원하기 위해 형변환 함수 제공한다. 코틀린의 특징 형변환시 발생할 수 있는 오류를 막기 위해 다른 언어들이 지원하는 '암시적 형변환'은 지원하지 않음 명시적 형변환 - 변환될 자료형을 개발자가 직접 지정함 암시적 형변환 - 변수를 할당할 시 자료형을 지정하지 않아도 자동으로 형변환 됨 배열- 내부적으로 Array 클래스로 제공되는 기능 var intArr = arrayOf(1,2,3,4,5) var nullArr = arrayOfNulls(5) intArr[2] = 8 println(intArr[4]) https://www.youtube.com/watch?v=tvtNch-GPEU *유튜브..
함수나 변수 이름은 카멜 표기법을 권장 (첫 단어만 소문자로 시작) 변수의 선언 val - 선언시에만 초기화 가능, 중간에 값을 변경할 수 없음 (runtime 시 변경되지 말아야 할 값 선언) var - 일반적으로 통용되는 변수, 언제든지 읽기 쓰기가 가능 변수는 선언 위치에 따라 두가지 이름 클래스에 선언된 변수 - property(속성) 이 외의 Scope 내에 선언된 변수 - Local Variable(로컬변수) kotlin의 차별점 변수가 선언된 후 초기화되지 않으면 기본값으로 초기화되거나 값이 할당되지 않았다는 뜻으로 null 값을 가짐 코틀린은 기본 변수에서 null을 허용하지 않으며 변수에 값을 할당하지 않은 채로 사용하면 문법 에러를 표시하고 컴파일을 막아주므로 의도치 않은 동작이나 nu..