Flat Asterisk Pyramid
Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 91 of 93.
Challenge
MediumRead 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
4Operators Part 1
Arithmetic OperatorsModulo OperatorAugmented AssignmentComparison OperatorsRecap - Simple Math7Basic IO
Println FunctionString TemplatesReadLine InputType ConversionRecap - Years Until RetirementRecap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesNamed ArgumentsDefault ValuesSingle Expression FunctionsRecap - Sigma FunctionRecap - Validation Function2Variables
Val vs VarType InferenceNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Logical Operators Part 3Ternary With If ExpressionRecap - Simple Logic8Bill Split Calculator
Welcome MessageGetting Input3Nullability
What Is Null SafetyNullable TypesSafe Call OperatorElvis OperatorFunction Challenge BasicsNot Null AssertionRecap - Safe Access6Decision Making
If StatementIf - ElseIf As An ExpressionWhen ExpressionWhen With RangesRecap - Simple Calculator9Loops
For LoopWhile LoopDo-While LoopBreakContinueRanges In LoopsNested LoopRecap - FactorialRecap - Dynamic InputPractice on your own: Kotlin playground