helloworld, var, const
This commit is contained in:
parent
e715d9278a
commit
885b864baf
@ -4,7 +4,11 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="495445f0-1eca-47b4-946d-d66cf898be6c" name="Changes" comment="" />
|
||||
<list default="true" id="495445f0-1eca-47b4-946d-d66cf898be6c" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/bilibili/src/go_code/project01/main/hello.go" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/bilibili/src/go_code/project02/main/main.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@ -18,6 +22,9 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="GOROOT" url="file:///usr/local/go" />
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 7
|
||||
}</component>
|
||||
@ -28,12 +35,14 @@
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"DefaultGoTemplateProperty": "Go File",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"go.import.settings.migrated": "true",
|
||||
"go.sdk.automatically.set": "true",
|
||||
"last_opened_file_path": "/Users/chenqiang/workspace/study/go",
|
||||
|
37
bilibili/src/const/test.go
Normal file
37
bilibili/src/const/test.go
Normal file
@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
// 可以在const()添加一个关键字iota,每行的iota都会累加1, 第一行的iota默认值是0
|
||||
BEIJING = 10 * iota
|
||||
SHANGHAI
|
||||
SHENZHEN
|
||||
)
|
||||
|
||||
const (
|
||||
a, b = iota + 1, iota + 2 // iota = 0, a = 1, b = 2
|
||||
c, d // iota = 1, c = 2, d = 3
|
||||
e, f // iota = 2, e = 3, f = 4
|
||||
g, h = iota * 2, iota * 3 // iota = 3, g = 3 * 2 = 6, h = 3 * 3 = 9
|
||||
i, k // iota = 4, i = 4 * 2 = 8, k = 4 * 3 = 12
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 常量(只读属性)
|
||||
const length int = 10
|
||||
|
||||
fmt.Println("length = ", length)
|
||||
|
||||
fmt.Println("BEIJING = ", BEIJING)
|
||||
fmt.Println("SHANGHAI = ", SHANGHAI)
|
||||
fmt.Println("SHENZHEN = ", SHENZHEN)
|
||||
|
||||
fmt.Println("a = ", a, "b = ", b)
|
||||
fmt.Println("c = ", c, "d = ", d)
|
||||
fmt.Println("e = ", e, "f = ", f)
|
||||
fmt.Println("g = ", g, "h = ", h)
|
||||
fmt.Println("i = ", i, "k = ", k)
|
||||
}
|
12
bilibili/src/hello.go
Normal file
12
bilibili/src/hello.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello Go!")
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
60
bilibili/src/var/test.go
Normal file
60
bilibili/src/var/test.go
Normal file
@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
四种声明变量的方式
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var gA int = 100
|
||||
var gB = 200
|
||||
|
||||
func main() {
|
||||
// 方法一:声明一个亦是 默认的值是0
|
||||
var a int
|
||||
fmt.Println("a = ", a)
|
||||
fmt.Printf("type of a is %T\n", a)
|
||||
|
||||
// 方法二:声明一个变量,初始化一个值
|
||||
var b int = 100
|
||||
fmt.Println("b = ", b)
|
||||
fmt.Printf("type of b = %T\n", b)
|
||||
|
||||
var bb string = "abcd"
|
||||
fmt.Printf("bb = %s\ntype of bb is %T\n", bb, bb)
|
||||
|
||||
// 方法三:在初始化的时候,可以省去数据类型,通过值自动匹配当前的变量的数据类型
|
||||
var c = 100
|
||||
fmt.Println("c = ", c)
|
||||
fmt.Printf("type of c = %T\n", c)
|
||||
|
||||
var cc = "abcd"
|
||||
fmt.Printf("cc = %s\ntype of cc is %T\n", cc, cc)
|
||||
|
||||
// 方法四:(常用的方法)省略var关键字,直接自动匹配,:=只能用在函数体内,不能用于声明全局变量
|
||||
e := 100
|
||||
fmt.Println("e = ", e)
|
||||
fmt.Printf("type of e is %T\n", e)
|
||||
|
||||
g := 3.14
|
||||
fmt.Println("g = ", g)
|
||||
fmt.Printf("type of g is %T\n", g)
|
||||
|
||||
// ====
|
||||
fmt.Println("gA = ", gA, ", gB = ", gB)
|
||||
|
||||
// 声明多个变量
|
||||
var xx, yy int = 100, 200
|
||||
fmt.Println("xx = ", xx, ", yy = ", yy)
|
||||
var kk, ll = 100, "Alice"
|
||||
fmt.Println("kk = ", kk, ", ll = ", ll)
|
||||
|
||||
// 多行多变量声明
|
||||
var (
|
||||
vv int = 100
|
||||
jj bool = true
|
||||
)
|
||||
fmt.Println("vv = ", vv, ", jj = ", jj)
|
||||
}
|
8
flysnow/.idea/.gitignore
vendored
Normal file
8
flysnow/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
9
flysnow/.idea/flysnow.iml
Normal file
9
flysnow/.idea/flysnow.iml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
8
flysnow/.idea/modules.xml
Normal file
8
flysnow/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/flysnow.iml" filepath="$PROJECT_DIR$/.idea/flysnow.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
flysnow/.idea/vcs.xml
Normal file
6
flysnow/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Loading…
Reference in New Issue
Block a user