Blogumuza Hoşgeldiniz

Bu blog sayfasında elimizden geldiğince algoritma ve yazılım hakkında makaleler paylaşacağız, yararlı olması ve yararlanmak dileğiyle ..,
Bizi takip edin. Daha fazlasını öğrenin...

Richard Stallman - Özgür Yazılım



Richard Stallman - Özgür Yazılım










Okumaya Devam et

Visual Basic - Read File Line by Line in The Visual Studio

Imports System.IO

Module Module1

    Sub Main()

        Dim path As String = Directory.GetCurrentDirectory()
        path = Directory.GetParent(Directory.GetParent(path).ToString()).ToString()
        Dim file As StreamReader = New StreamReader(path & "\\file.txt")
        Dim str As String
        str = file.ReadLine()
        While (str IsNot Nothing)
            Console.WriteLine(str.ToString())
            str = file.ReadLine()
        End While
        Console.ReadLine()
    End Sub

End Module


Okumaya Devam et

Recursive Fibonacci Neden Yavaş?

Okumaya Devam et

Go Programming - Variables

Variables

package main

import "fmt"

func main() {
    var x string = "Hello World"
    fmt.Println(x)
}
 

OR
 
package main

import "fmt"

func main() {
    var x string
    x = "Hello World"
    fmt.Println(x)
} 
 
$ go run main.go

Hello World
 
 

package main

import "fmt"

func main() {
    var x string
    x = "first"
    fmt.Println(x)
    x = "second"
    fmt.Println(x)
} 
 
$ go run main.go
fist second 

    var x string = "hello"
    var y string = "world"
    fmt.Println(x == y)
 
This program should print false because hello is not the same as world. On the other hand:

    var x string = "hello"
    var y string = "hello"
    fmt.Println(x == y)
This will print true because the two strings are the same.

Since creating a new variable with a starting value is so common Go also supports a shorter statement:

    x := "Hello World"
 
Notice the : before the = and that no type was specified. The type is not necessary because the Go compiler is able to infer the type based on the literal value you assign the variable. (Since you are assigning a string literal, x is given the type string) The compiler can also do inference with the var statement:

    var x = "Hello World"
 
The same thing works for other types:

    x := 5
    fmt.Println(x)
 
Generally you should use this shorter form whenever possible.

Example:

dogsName := "Max"
    fmt.Println("My dog's name is", dogsName)
 
$ go run main.go 
My dog's name is Max

Okumaya Devam et

Go Programming - Types

Integer

package main

import "fmt"

func main() {
    fmt.Println("1 + 1 =", 1 + 1)
}
 
If you run the program and you should see this:

$ go run main.go
1 + 1 = 2
 
In addition to addition Go has several other operators:
+addition
-subtraction
*multiplication
/division
%remainder

Strings

package main

import "fmt"

func main() {
    fmt.Println(len("Hello World"))
    fmt.Println("Hello World"[1])
    fmt.Println("Hello " + "World")
}


Running this program should give you:

$ go run main.go 
10
e
Hello World

Booleans

&&and
||or
!not
Here is an example program showing how they can be used:

func main() {
    fmt.Println(true && true)
    fmt.Println(true && false)
    fmt.Println(true || true)
    fmt.Println(true || false)
    fmt.Println(!true)
}
Running this program should give you:
$ go run main.go
true
false
true
true
false


We usually use truth tables to define how these operators work:
ExpressionValue
true && true= true
true && false= false
false && true= false
false && false= false
ExpressionValue
true || true= true
true || false= true
false || true= true
false || false= false
ExpressionValue
!true= false
!false= true
Okumaya Devam et

Go Programming - Functions


package main

import "fmt"

func add(x int, y int) int {

    return x + y

}

func main() {

    fmt.Println(add(42, 13))

} 

Okumaya Devam et

Go Programming - Hello World

package main

import "fmt"

func main() {

    fmt.Println("Hello World")

}
Okumaya Devam et