@@ -420,13 +420,13 @@ package main
420
420
import " fmt"
421
421
422
422
func double (i int ) {
423
- i = i * 2
423
+ i = i * 2
424
424
}
425
425
426
426
func main () {
427
- i := 2
428
- double (i)
429
- fmt.Printf (" i = %v \n " , i)
427
+ i := 2
428
+ double (i)
429
+ fmt.Printf (" i = %v \n " , i)
430
430
}
431
431
```
432
432
@@ -438,13 +438,13 @@ package main
438
438
import " fmt"
439
439
440
440
func double (i *int ) {
441
- *i = *i * 2
441
+ *i = *i * 2
442
442
}
443
443
444
444
func main () {
445
- i := 2
446
- double (&i)
447
- fmt.Printf (" i = %v \n " , i)
445
+ i := 2
446
+ double (&i)
447
+ fmt.Printf (" i = %v \n " , i)
448
448
}
449
449
```
450
450
@@ -469,11 +469,11 @@ func main() {
469
469
width: 4.0 ,
470
470
}
471
471
fmt.Printf (" square has area of %v \n " , square.height * square.width )
472
- }
472
+ }
473
473
```
474
474
475
475
* A struct is like a final class in Java.
476
- * Variables starting with a upper case letter are public, variables starting with lower case letter are package private.
476
+ * Variables starting with an upper case letter are public, variables starting with a lower case letter are package private.
477
477
478
478
26 Methods
479
479
----------
@@ -555,15 +555,15 @@ Go has some pre-defined interfaces. The most important ones are:
555
555
556
556
``` go
557
557
type Stringer interface {
558
- String () string
558
+ String () string
559
559
}
560
560
```
561
561
562
562
Like Java's ` toString() `
563
563
564
564
``` go
565
565
type error interface {
566
- Error () string
566
+ Error () string
567
567
}
568
568
```
569
569
@@ -578,15 +578,16 @@ The following code:
578
578
579
579
``` go
580
580
func main () {
581
- c := &circle{
582
- radius: 2.0 ,
583
- }
584
- r := &rectangle{
585
- width: 4.0 ,
586
- height: 4.0 ,
587
- }
588
- fmt.Printf (" Shape 1: %v \n " , c)
589
- fmt.Printf (" Shape 2: %v \n " , r)}
581
+ c := &circle{
582
+ radius: 2.0 ,
583
+ }
584
+ r := &rectangle{
585
+ width: 4.0 ,
586
+ height: 4.0 ,
587
+ }
588
+ fmt.Printf (" Shape 1: %v \n " , c)
589
+ fmt.Printf (" Shape 2: %v \n " , r)
590
+ }
590
591
```
591
592
592
593
Should produce the following output:
@@ -746,15 +747,15 @@ Write a function `combine()` such that
746
747
747
748
``` go
748
749
func main () {
749
- add := func (a, b int ) int {
750
- return a + b
751
- }
752
- mult := func (a, b int ) int {
753
- return a * b
754
- }
755
- arr := createArray (10 )
756
- fmt.Printf (" add(1..10)=%v \n " , combine (arr, add))
757
- fmt.Printf (" mult(1..10)=%v \n " , combine (arr, mult))
750
+ add := func (a, b int ) int {
751
+ return a + b
752
+ }
753
+ mult := func (a, b int ) int {
754
+ return a * b
755
+ }
756
+ arr := createArray (10 )
757
+ fmt.Printf (" add(1..10)=%v \n " , combine (arr, add))
758
+ fmt.Printf (" mult(1..10)=%v \n " , combine (arr, mult))
758
759
}
759
760
```
760
761
@@ -944,7 +945,7 @@ func main() {
944
945
46 Exercise
945
946
-----------
946
947
947
- Include a unique number in each respone :
948
+ Include a unique number in each response :
948
949
949
950
* First response gets number 1
950
951
* Second response gets number 2
0 commit comments