Go language test code

Source: Internet
Author: User

Learn the go language for the first time, test the code

Package MainImport "FMT"var age int;const sex=0func init () {FMT. Println ("Mr_man") Age= 9FMT. Println (age)}func main () {FMT. Println ("Hello World", Sex) xxx () fmt. Println ("=========================") const LENGTH int= 10const WIDTH INT= 5var area int const A, B, C= 1, False,"Str" Area= LENGTH *WIDTH FMT. Printf ("area is:%d", area) println () println (A, B, c) println ("========================") Compute () compare () Focuss () Maxx (2, 3) Showyanghuitriangle () Mei ()}func xxx () {fmt. Println ("Mr_zhang") fmt. Println ("I'm the one that was triggered in the main function.") const (a=Iota B c D="ha"E F= 100G H=iota i) fmt. Println (A, B, C, D, E, F, G, H, i)}func compute () {var a int= 21var b int= 10var c int c= A +FMT B. Printf ("first row-the value of C is:%d \ n", c) C= A-FMT B. Printf ("second row-the value of C is:%d \ n", c) C= A *FMT B. Printf ("third row-the value of C is:%d \ n", c) C= A/FMT B. Printf ("line fourth-the value of C is:%d \ n", c) C= a%FMT B. Printf ("Line Fifth-the value of C is:%d \ n", c) a++FMT. Printf ("line Sixth-the value of C is:%d \ n", a) a= 21a--FMT. Printf ("the value of line Seventh-C is:%d \ n", a)} Func compare () {var a int= 21var b int= 10if(A = =b) {fmt. Printf ("first line-a equals b \ n")    } Else{fmt. Printf ("first line-A is not equal to B \ n")    }    if(A <b) {fmt. Printf ("second row-a less than B")    } Else{fmt. Printf ("second row-A is not less than b \ n")    }    if(A >b) {fmt. Printf ("line three-a greater than B \ n")    } Else{fmt. Printf ("Line Three-A is not much more than b \ n")} a= 5b= 20if(A <=b) {fmt. Printf ("Line Fourth-A is less than or equal to B \ n")    }    if(b >=a) {fmt. Printf ("Line Fifth-B is greater than or equal to a \ n")}}func Focuss () {var a int= 4var b int32 var c float32 var ptr*int FMT. Printf ("first row-the type of a variable =%T \ n", a) fmt. Printf ("second row-b variable type =%T \ n", b) fmt. Printf ("line three-c variable type =%T \ n", c) PTR= &a FMT. Printf ("A has a value of%d \ n", a) fmt. Printf ("*ptr is%d \ n", *ptr)} Func Maxx (NUM1, num2 int) int {fmt. Println ("===========>maxx") var result intif(Num1 >num2) {Result=NUM1}Else{result=num2} fmt. PRINTLN (Result)returnresult}//number of rows const LINES int= 10//Yang Hui triangle func showyanghuitriangle () {nums:=[]int{} forI: = 0; i < LINES; i++ {        //Fill Blank forJ: = 0; J < (Lines-i); J + +{fmt. Print (" ")        }         forJ: = 0; J < (i + 1); J + +{var length=Len (nums) var value intifj = = 0 | | j = =I {value= 1            } Else{Value= Nums[length-i] + nums[length-i-1]} nums=Append (nums, value) fmt. Print (Value," ")} FMT. Println ("")}}func Mei () {var n [10] int var i, J int fori = 0; I < 10; i++{N[i]= i + 100    }     forj = 0; J < 10; J + +{fmt. Printf ("element[%d] =%d\n", J, N[j])}}

Go language test code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.