A Tour of Go Exercise: Loops and Functions】的更多相关文章

As a simple way to play with functions and loops, implement the square root function using Newton's method. In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating: To begin with, just repeat that calc…
Let's have some fun with functions. Implement a fibonacci function that returns a function (a closure) that returns successive fibonacci numbers. package main import "fmt" // fibonacci is a function that returns // a function that returns an int…
Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values. The choice…
Operator : While Loop : For Loop :  Arrays : Code : public class FirstJavaClass { public static void main(String[] args) { int arr[] = new int[5]; arr[0]=78; arr[1]=980; arr[2]=98; arr[3]=9; arr[4]=765; System.out.println(arr[2]); System.out.println(…
Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data. Define your own Image type, implement the necessary methods, and callpic.ShowImage. B…
Implement the following types and define ServeHTTP methods on them. Register them to handle specific paths in your web server. type String string type Struct struct { Greeting string Punct string Who string } For example, you should be able to regist…
Copy your Sqrt function from the earlier exercises and modify it to return an error value. Sqrt should return a non-nil error value when given a negative number, as it doesn't support complex numbers. Create a new type type ErrNegativeSqrt float64 an…
Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Test function runs a test suite against the provided function and prints success or failure. You might find strings.Fields helpful. package main import (…
/* Exercise: Loops and Functions #43 */ package main import ( "fmt" "math" ) func Sqrt(x float64) float64 { z := float64(.) s := float64() for { z = z - (z*z - x)/(*z) { break } s = z } return s } func main() { fmt.Println(Sqrt()) fmt.…
C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very early draft. It is inkorrekt, incompleat, and pµøoorly formatted. Had it been an open source (code) project, this would have been release 0.6. Copy…