给程序输入加上换行符

This commit is contained in:
Jeff
2015-03-16 12:28:12 +08:00
parent 029f6ece17
commit 2ef71c181e

View File

@@ -84,19 +84,19 @@ slice 在内存中的组织方式实际上是一个有 3 个域的结构体:
//slice1 = slice1[0:7 ] // panic: runtime error: slice bound out of range
}
输出
Slice at 0 is 2
Slice at 1 is 3
Slice at 2 is 4
The length of arr1 is 6
The length of slice1 is 3
The capacity of slice1 is 4
Slice at 0 is 2
Slice at 1 is 3
Slice at 2 is 4
Slice at 3 is 5
The length of slice1 is 4
The capacity of slice1 is 4
输出
Slice at 0 is 2
Slice at 1 is 3
Slice at 2 is 4
The length of arr1 is 6
The length of slice1 is 3
The capacity of slice1 is 4
Slice at 0 is 2
Slice at 1 is 3
Slice at 2 is 4
Slice at 3 is 5
The length of slice1 is 4
The capacity of slice1 is 4
如果 s2 是一个 slice你可以将 s2 向后移动一位 `s2 = s2[1:]`但是末尾没有移动slice 只能向后移动`s2 = s2[-1:]` 会导致编译错误slice 不能被重新分片以获取数组的前一个元素
@@ -162,19 +162,19 @@ make 的使用方式是:`func make([]T, len, cap)` 其中 cap 是可选参数
fmt.Printf("The capacity of slice1 is %d\n", cap(slice1))
}
输出结构
Slice at 0 is 0
Slice at 1 is 5
Slice at 2 is 10
Slice at 3 is 15
Slice at 4 is 20
Slice at 5 is 25
Slice at 6 is 30
Slice at 7 is 35
Slice at 8 is 40
Slice at 9 is 45
The length of slice1 is 10
The capacity of slice1 is 10
输出结构
Slice at 0 is 0
Slice at 1 is 5
Slice at 2 is 10
Slice at 3 is 15
Slice at 4 is 20
Slice at 5 is 25
Slice at 6 is 30
Slice at 7 is 35
Slice at 8 is 40
Slice at 9 is 45
The length of slice1 is 10
The capacity of slice1 is 10
因为字符串是纯粹不可变的字节数组它们也可以被切分成 slice