본문 바로가기

IT254

88] 프로그래머스 숨어있는 숫자의 덧셈 (1) Kotlin char는 toInt 했을때 int가 반환되지 않는다. char.toString().toInt() 해줘야한다. class Solution { fun solution(my_string: String): Int { var answer: Int = 0 for(i in 0 until my_string.length){ if(my_string[i] in '1' .. '9') { answer += my_string[i].toString().toInt() } } return answer } } https://kotlinworld.com/436 [Kotlin] Char을 Int로 변환하는 세가지 방법 알아보기 : Char to IntChar을 Int로 변환할 때 많은 실수가 생기는 이유 Kotlin은 하나의 자료형을 다.. 2023. 10. 23.
87] 프로그래머스 짝수는 싫어요 kotlin class Solution { fun solution(n: Int): IntArray { val mulist = mutableListOf() for(i in 0 .. n) { if(i%2 == 1) mulist.add(i) } return mulist.toIntArray() } } https://hwan-shell.tistory.com/247 Kotlin] MutableList 기능 설명1. MutableListKotlin의 List에는 List와 MutableList가 있습니다.List는 읽기 전용이며 MutableList는 읽기/ 쓰기가 가능합니다. Kotlin에선 List인 listOf의 사용을 권장하고 있습니다. (코드의 선명함과 안정성 때hwan-shell.tistory.com 2023. 10. 15.
86] 프로그래머스 모음 제거 Kotlin class Solution { fun solution(myString: String) = myString.replace("a|e|i|o|u".toRegex(), "") }class Solution { fun solution(my_string: String): String { var answer: String = "" return my_string.filterNot{ "aeiou".contains(it) } } } class Solution { fun solution(my_string: String): String { var answer: String = "" var momo = "aeiou" for(i in 0 until my_string.length) { if(!momo.contains(my_strin.. 2023. 10. 15.
85 프로그래머스] 최댓값 만들기(1) kotlin class Solution { fun solution(numbers: IntArray): Int { var answer: Int = 0 numbers.sort() answer = numbers[numbers.size -1] * numbers[numbers.size -2] return answer } } https://skytitan.tistory.com/184 [코틀린] 배열 정렬하기 원본 배열 정렬 1. sort() 원본 배열을 오름차순으로 정렬한다. import java.util.* fun main() { var arr = arrayOf(0, 7, 4, 3, 2, 6, 5, 1 ) arr.sort() println(Arrays.toString(arr)) /* 결과 [0, 1, 2, 3, 4, 5, 6.. 2023. 10. 14.