| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package main
- import (
- "fmt"
- "strings"
- )
- func main() {
- batTest()
- // ExampleStringer()
- // foo1()
- /*
- value1, value2, operation := readTask()
- switch v1 := value1.(type) {
- case float64:
- break
- default:
- fmt.Printf("value=%v: %T\n", v1, v1)
- return
- }
- switch v2 := value2.(type) {
- case float64:
- break
- default:
- fmt.Printf("value=%v: %T\n", v2, v2)
- return
- }
- switch op := operation.(type) {
- case string:
- if op == "+" {
- fmt.Printf("%.4f\n", value1.(float64)+value2.(float64))
- } else if op == "-" {
- fmt.Printf("%.4f\n", value1.(float64)-value2.(float64))
- } else if op == "*" {
- fmt.Printf("%.4f\n", value1.(float64)*value2.(float64))
- } else if op == "/" {
- fmt.Printf("%.4f\n", value1.(float64)/value2.(float64))
- }
- default:
- fmt.Printf("operation=%v: %T\n", op, op)
- return
- }
- // fmt.Println("value 1 - OK")
- // fmt.Println(value1, value2, operation)
- */
- }
- func foo1() {
- // vi1, vi2, operation := readTask()
- // vi := [2]interface{}{vi1, vi2}
- var v1, v2 float64
- vf := [2]*float64{&v1, &v2}
- fmt.Println(vf)
- fmt.Printf("%v %T", vf, vf)
- }
- func readTask() (v1, v2, op interface{}) {
- v1 = 12.36
- v2 = 36.24
- op = "+"
- return
- }
- type Animal struct {
- Name string
- Age uint
- }
- func (a Animal) String() string {
- return fmt.Sprintf("%v (%d)", a.Name, a.Age)
- }
- func ExampleStringer() {
- a := Animal{
- Name: "Gopher",
- Age: 2,
- }
- fmt.Println(a)
- }
- type Battery struct {
- capacity int
- }
- func (b Battery) String() string {
- var ret string = "["
- for i := 0; i < (10 - b.capacity); i++ {
- ret += " "
- }
- for i := 0; i < b.capacity; i++ {
- ret += "X"
- }
- ret += "]"
- return ret
- }
- func batTest() {
- // var batteryForTest Battery
- var charge string
- batteryForTest := Battery{}
- fmt.Scan(&charge)
- batteryForTest.capacity = strings.Count(charge, "1")
- fmt.Println(batteryForTest)
- }
|