Star Print Problem Using Swift For-Loop - Question02

Star Print Problem Using Swift For-Loop.

I am a swift beginner.
The teacher gave me the questions.
I tried to work for it.
However, the teacher expect me to give another solutions.
Could anybody give me some suggestions?

//Question02

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

// Write down a function with 2 arguments ("X", "Y")

func startPrintStarQ2(x: Int, y: Int) -> String {
    let finalResult = null
    
    // please start your implementation to present the Q2 result

    return finalResult
}

For Question02, I tried the basic method.

let stars = ["    **  " , "  ****** ", "   ****  " , " ********" , "  ****** " , "**********"]

for star in stars {
    
    print("\(star)")
    
}

However, the teacher expect me to give another solutions.

I am trying to do the research.

Could anyone can give me some suggestions?

Thank you.

I like your basic method, but it gets pretty tedious as the row count grows. Again I'd look at String.init(repeating:count:), but you need two, one for the spaces at the start of the line, one for the *s.

2 Likes

@JohnBlackburne
Thank you for your comments.

May I ask you give me more details / more hints?

Thank you