Skip to content

Commit 87796a1

Browse files
committed
Add Shapes solution code
1 parent 1ceb819 commit 87796a1

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

5-loops/Shapes.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
fun main() {
2+
3+
// Square Variables
4+
val sqSide = 7
5+
val sqChar1 = "X "
6+
val sqChar2 = "O "
7+
8+
// Write your code below
9+
for (i in 1..sqSide) {
10+
for (j in 1..sqSide) {
11+
if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 ==1) {
12+
print(sqChar1)
13+
} else {
14+
print(sqChar2)
15+
}
16+
}
17+
println()
18+
}
19+
20+
// Triangle Variables
21+
val triRows = 10
22+
var triCount = 0
23+
var triRowLen = triRows
24+
val triChar1 = "/ "
25+
val triChar2 = " "
26+
27+
// Write your code below
28+
for (i in triRows downTo 1) {
29+
while (triCount < triRowLen) {
30+
triCount++
31+
print(triChar1)
32+
}
33+
println()
34+
triCount = 0
35+
triRowLen--
36+
}
37+
38+
triRowLen = triRows
39+
for (i in triRows downTo 1) {
40+
while (triCount < triRowLen) {
41+
triCount++
42+
if (triCount != 1 && triCount != triRowLen && i != triRows) {
43+
print(triChar2)
44+
} else {
45+
print(triChar1)
46+
}
47+
}
48+
println()
49+
triCount = 0
50+
triRowLen--
51+
}
52+
}

0 commit comments

Comments
 (0)