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 to have another solutions.
Could anybody give me some suggestions?
*
***
**
****
***
*****
func startPrintStarQ1(x: Int, y: Int) -> String {
let finalResult = null
return finalResult
}
AND
**
******
****
********
******
**********
func startPrintStarQ2(x: Int, y: Int) -> String {
let finalResult = null
return finalResult
}
What I have tried:
For Question01, I tried to do in this way.
for i in 1...2 {
for _ in 1...i {
print("*", terminator: "")
}
for k in 1..<i {
print("*", terminator: "")
}
print("")
}
for a in 2...3 {
for _ in 1...a {
print("*", terminator: "")
}
for k in 2..<a {
print("*", terminator: "")
}
print("")
}
for b in 2...3 {
for _ in 1...b {
print("*", terminator: "")
}
for k in 1..<b {
print("*", terminator: "")
}
print("")
}
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.