Menu
Coddy logo textTech

Flat Asterisk Pyramid

Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 91 of 93.

challenge icon

Challenge

Medium

Read an integer n from input and print a flat asterisk pyramid where each group contains an increasing number of asterisks, all on a single line separated by spaces.

The pattern should have:

  • Group 1: 1 asterisk
  • Group 2: 2 asterisks
  • Group 3: 3 asterisks
  • ...and so on until group n

Each group of asterisks should be separated by a single space. There should be no trailing space at the end of the output.

Input format:

A single integer n representing the number of groups.

Output format:

A single line containing the flat pyramid pattern.

Example:

If the input is 4, the output should be:

* ** *** ****

If the input is 6, the output should be:

* ** *** **** ***** ******

Try it yourself

fun main() {
    // Read input
    val n = readLine()!!.toInt()
    
    // TODO: Write your code below
    // Build the flat pyramid pattern with groups of asterisks
    // Group 1 has 1 asterisk, Group 2 has 2 asterisks, etc.
    // Separate each group with a single space
    
    
    // Output the result (no trailing space)
    // println(result)
}

All lessons in Fundamentals

Practice on your own: Kotlin playground