Commit c21c32ec by Susi Susanti

belajar go h 1

parent 8e104672
package main
import "fmt"
func helloWord() {
fmt.Println("HELLO WORD")
}
package main
import "fmt"
const DB_NAME = "IPS"
type VegetablePrice struct {
cucumber int
chili int
}
func main() {
fmt.Println("====================== 1")
fmt.Println("new word")
fmt.Println("====================== 2")
helloWord()
fmt.Println("====================== 3")
price := 1000
fmt.Println(price)
fmt.Println("====================== 4")
var a, b = 6, "Hello"
var c, d = 7, "World!"
fmt.Println(a, b)
fmt.Println(c, d)
fmt.Println("====================== 5")
fmt.Println(DB_NAME)
fmt.Println("====================== 6")
var e, f = 21, "hello"
fmt.Printf("value e : %v and f : %v\n", e, f)
fmt.Println("====================== 7")
g := true
h := 3.14
fmt.Printf("value bool : %v and value float %v\n", g, h)
fmt.Println("====================== 8")
i := [2]string{"new", "word"}
j := [3]int{1, 2, 3}
k := [...]string{"a", "b", "c"}
fmt.Printf("value i : %v , value j : %v and value k : %v\n", i, j, k)
fmt.Println("====================== 9")
l := [...]int{1, 2, 3, 4}
fmt.Printf("length l : %v", len(l))
fmt.Println("====================== 10")
m := []int{1, 2, 3, 4, 5, 6}
fmt.Printf("value %v", m[:len(m)-2])
fmt.Println("====================== 11")
n := 5 + 5
o := 5 - 3
p := 6 % 4
fmt.Printf("value n : %v , value o : %v and value p : %v\n", n, o, p)
fmt.Printf("====================== 12\n")
q := 4
r := 2
if q > r {
fmt.Println(q > r)
}
if q < r {
fmt.Printf("hasil q < r : %v", q < r)
} else if q == r {
fmt.Printf("hasil q == r : %v", q == r)
} else {
fmt.Printf("hasil q > r : %v", q > r)
}
fmt.Printf("====================== 13\n")
s := 4
switch s {
case 1, 5:
fmt.Println("bukan 1 dan 5")
case 2:
fmt.Println("bukan 2")
case 3:
fmt.Println("bukan 3")
case 4, 6:
fmt.Println("nah valuenya 4 or 6")
}
fmt.Printf("====================== 14\n")
MyNewFunc()
fmt.Printf("====================== 15\n")
MyWord("susi belajar go")
fmt.Printf("====================== 16\n")
fmt.Println(SumData(5, 3))
fmt.Printf("====================== 17\n")
fmt.Println(SumData2(5, 3))
fmt.Printf("====================== 18\n")
var market VegetablePrice
market.chili = 10000
market.cucumber = 120000
fmt.Printf("chili price : %v\n", market.chili)
fmt.Printf("chili cucumber : %v\n", market.cucumber)
fmt.Printf("====================== 19\n")
Market(market)
fmt.Printf("====================== 20\n")
t := map[string]string{"name": "pockcoy", "price": "1000", "qty": "5"}
u := map[string]any{"name": "pockcoy", "price": 200, "qty": 400}
fmt.Printf("value t : %v\n", t)
fmt.Printf("value u : %v\n", u)
}
func MyNewFunc() {
fmt.Printf("new func\n")
}
func MyWord(name string) {
fmt.Printf("value name %v\n", name)
}
func SumData(x int, y int) int {
return x + y
}
func SumData2(x int, y int) (result int) {
result = x - y
return result
}
func Market(vege VegetablePrice) {
fmt.Printf("chili price : %v\n", vege.chili)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment