diff --git a/eBook/exercises/chapter_4/count_characters.go b/eBook/exercises/chapter_4/count_characters.go index 1fc0ce2..abc3258 100755 --- a/eBook/exercises/chapter_4/count_characters.go +++ b/eBook/exercises/chapter_4/count_characters.go @@ -1,22 +1,23 @@ -package main - -import ( - "fmt" - "unicode/utf8" -) - -func main() { - // count number of characters: - str1 := "asSASA ddd dsjkdsjs dk" - fmt.Printf("The number of bytes in string str1 is %d\n",len(str1)) - fmt.Printf("The number of characters in string str1 is %d\n",utf8.RuneCountInString(str1)) - str2 := "asSASA ddd dsjkdsjsこん dk" - fmt.Printf("The number of bytes in string str2 is %d\n",len(str2)) - fmt.Printf("The number of characters in string str2 is %d",utf8.RuneCountInString(str2)) -} -/* Output: -The number of bytes in string str1 is 22 -The number of characters in string str1 is 22 -The number of bytes in string str2 is 28 -The number of characters in string str2 is 24 -*/ \ No newline at end of file +package main + +import ( + "fmt" + "unicode/utf8" +) + +func main() { + // count number of characters: + str1 := "asSASA ddd dsjkdsjs dk" + fmt.Printf("The number of bytes in string str1 is %d\n", len(str1)) + fmt.Printf("The number of characters in string str1 is %d\n", utf8.RuneCountInString(str1)) + str2 := "asSASA ddd dsjkdsjsこん dk" + fmt.Printf("The number of bytes in string str2 is %d\n", len(str2)) + fmt.Printf("The number of characters in string str2 is %d", utf8.RuneCountInString(str2)) +} + +/* Output: +The number of bytes in string str1 is 22 +The number of characters in string str1 is 22 +The number of bytes in string str2 is 28 +The number of characters in string str2 is 24 +*/ diff --git a/eBook/exercises/chapter_4/divby0.go b/eBook/exercises/chapter_4/divby0.go index 36cfe6c..5a87c36 100755 --- a/eBook/exercises/chapter_4/divby0.go +++ b/eBook/exercises/chapter_4/divby0.go @@ -1,8 +1,8 @@ -package main - -func main() { - a, b := 10, 0 - c := a / b // panic: runtime error: integer divide by zero - - print(c) -} +package main + +func main() { + a, b := 10, 0 + c := a / b // panic: runtime error: integer divide by zero + + print(c) +} diff --git a/eBook/exercises/chapter_4/function_calls_function.go b/eBook/exercises/chapter_4/function_calls_function.go index 62711a4..315973a 100755 --- a/eBook/exercises/chapter_4/function_calls_function.go +++ b/eBook/exercises/chapter_4/function_calls_function.go @@ -1,18 +1,19 @@ -package main - -var a string // global scope - -func main() { - a = "G" - print(a) - f1() -} -func f1() { - a := "O" // new local variable a, only scoped within f1() ! - print(a) - f2() -} -func f2() { - print(a) // global variable is taken -} -// GOG \ No newline at end of file +package main + +var a string // global scope + +func main() { + a = "G" + print(a) + f1() +} +func f1() { + a := "O" // new local variable a, only scoped within f1() ! + print(a) + f2() +} +func f2() { + print(a) // global variable is taken +} + +// GOG diff --git a/eBook/exercises/chapter_4/global_scope.go b/eBook/exercises/chapter_4/global_scope.go index 080a295..6531ad1 100755 --- a/eBook/exercises/chapter_4/global_scope.go +++ b/eBook/exercises/chapter_4/global_scope.go @@ -1,19 +1,20 @@ -package main - -var a = "G" // global scope - -func main() { - n() - m() - n() -} - -func n() { - print(a) -} - -func m() { - a = "O" // simple assignment: global a gets a new value - print(a) -} -// GOO \ No newline at end of file +package main + +var a = "G" // global scope + +func main() { + n() + m() + n() +} + +func n() { + print(a) +} + +func m() { + a = "O" // simple assignment: global a gets a new value + print(a) +} + +// GOO diff --git a/eBook/exercises/chapter_4/local_scope.go b/eBook/exercises/chapter_4/local_scope.go index 785bf7e..4db59be 100755 --- a/eBook/exercises/chapter_4/local_scope.go +++ b/eBook/exercises/chapter_4/local_scope.go @@ -1,17 +1,18 @@ -package main - -var a = "G" // global (package) scope - -func main() { - n() - m() - n() -} -func n() { - print(a) -} -func m() { - a := "O" // new local variable a is declared - print(a) -} -// GOG \ No newline at end of file +package main + +var a = "G" // global (package) scope + +func main() { + n() + m() + n() +} +func n() { + print(a) +} +func m() { + a := "O" // new local variable a is declared + print(a) +} + +// GOG