The numbers that you want to print are the first 6 members of the sequence:
a(n) = n * (n + 1) /2
So you could print them with this loop:
for (i: Int in 1..6) {
println(i * (i + 1) / 2)
}
or:
(1..6).forEach { println(it * (it + 1) / 2) }
More Related Contents:
- startForeground fail after upgrade to Android 8.1
- Why do I get “unresolved reference” error for my view’s name/ID when I type it in Kotlin?
- Notify Observer when item is added to List of LiveData
- Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15
- Room Persistence: Error:Entities and Pojos must have a usable public constructor
- Singleton with parameter in Kotlin
- Error: Execution failed for task ‘:app:clean’. Unable to delete file
- How are Android activities handled with Jetpack Compose and Compose Navigation?
- The ‘kotlin-android-extensions’ Gradle plugin is deprecated
- Existing 3-function callback to Kotlin Coroutines
- Pass Parcelable argument with compose navigation
- Error:Execution failed for task ‘:app:kaptDebugKotlin’
- Jetpack Compose collapsing toolbar
- Could not deserialize object. Class does not define a no-argument constructor.If you are using ProGuard, make sure these constructors are not stripped
- Android – How to achieve setOnClickListener in Kotlin?
- Android Room – Select query with LIKE
- HTTP Request in Android with Kotlin
- Cannot find symbol DataBindingComponent on Android Studio 3.2 Canary 16 Kotlin project
- Kotiln: pass data from adapter to activity
- Different types of width in jetpack compose
- push notification enable and disable by using switch
- Can’t create new Kotlin project after updating to Android Studio 4.2
- Kotlin Android View Binding: findViewById vs Butterknife vs Kotlin Android Extension
- Close/hide the Android Soft Keyboard with Kotlin
- How I can retrieve current fragment in NavHostFragment?
- Kotlin Coroutines the right way in Android
- FragmentTransaction hide/show doesn’t work sometimes
- Kotlin Android debounce
- kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead
- Kotlin: open new Activity inside of a Fragment