add: array exercises

This commit is contained in:
Inanc Gumus
2018-12-05 15:02:03 +03:00
parent 25c15716b6
commit 91e17cbeb3
27 changed files with 690 additions and 113 deletions

View File

@@ -0,0 +1,25 @@
package main
// ---------------------------------------------------------
// EXERCISE: Wizard Printer
//
// In this exercise, your goal is to display a few famous scientists
// in a pretty table.
//
// 1. Create a multi-dimensional array
// 2. In each inner array, store the scientist's name, lastname and his/her
// nickname
// 3. Print their information in a pretty table using a loop.
//
// EXPECTED OUTPUT
// First Name Last Name Nickname
// ==================================================
// Albert Einstein time
// Isaac Newton apple
// Stephen Hawking blackhole
// Marie Curie radium
// Charles Darwin fittest
// ---------------------------------------------------------
func main() {
}

View File

@@ -0,0 +1,26 @@
package main
import (
"fmt"
"strings"
)
func main() {
names := [...][3]string{
{"First Name", "Last Name", "Nickname"},
{"Albert", "Einstein", "emc2"},
{"Isaac", "Newton", "apple"},
{"Stephen", "Hawking", "blackhole"},
{"Marie", "Curie", "radium"},
{"Charles", "Darwin", "fittest"},
}
for i := range names {
n := names[i]
fmt.Printf("%-15s %-15s %-15s\n", n[0], n[1], n[2])
if i == 0 {
fmt.Println(strings.Repeat("=", 50))
}
}
}