Learn free golang-examples tutorials


Golang Examples - remove/strp white spaces from a String

December 22, 2018 ·  3 min read

In this blog post, You will learn three programs using Strings package builtin functions Delete all whitespaces from a string Delete leading and trailing spaces of a string Remove duplicate spaces/tabs/newlines from a given string Example program to strip all whitespaces from a string This program is to remove the all white or empty spaces from a given string, return the new string Standard inbuilt Strings package provides various utility string functions....


Golang Example - Convert(cast) Hexadecimal to Decimal Integer Number vice versa

December 20, 2018 ·  4 min read

In this blog post, You will learn two programs in Go language, The first program is to convert Hexadecimal to Decimal Integer. The second program to convert Decimal to Hexadecimal Number. Golang Hexadecimal Number System Hexadecimal number is also called Hexa number which contains 16 digits ie numbers start from 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. It is based on the Base 16 ie Hexa number system. So HexaDecimal contains Decimal Numbers,0-9 (base 10) and Extra 6 alphabets - A to F...


Golang Example - Convert(cast) Octal to Decimal Number

December 20, 2018 ·  3 min read

In this blog post, You will learn two programs in Go language The first program is to convert Octal to Decimal Number The second program to convert Decimal to Octal Number. An Octal number is a number based on the base 8 number system. It contains digits from 0 to 7. In Golang, Octal numbers are always prefixed with zero Example octal numbers is 0879. Decimal Number are numbers which contain numbers based on base 10....


Golang Example - Convert(cast) Binary to Decimal or Decimal to Binary Number

December 20, 2018 ·  3 min read

In these posts, You will learn two programs in Go language The first program is to convert Binary Number to Decimal Number Second program to convert Decimal Number to Binary Number. A binary number is a number based on base 2. It contains either zero or one digits. Each digit is called a bit, Example binary numbers are 1011 Decimal Number are numbers which contain numbers based on base 10...


Golang Example - Calculate power or exponents of a Number

December 19, 2018 ·  3 min read

In this posts, You will learn Three programs to calculate a power of a number First program is to calculate power of a number Second program to find exponent of a number using Math pow function Third program is to find power of a number using recursive function Power of m with exponent n is also called m n which is product of number n with m times....


Golang Example - 3 ways to check Length of a String with output

December 18, 2018 ·  2 min read

In this blog post, You will learn three programs First program is Length or count of Character/bytes of a String Second program is Length of runes in a String  Third Program is to find the length of string using pointer String is sequence of characters which contains one or more words. In Golang, String is read only of arbitary bytes.String length is number of characters in a string, For example, Given input string is “Cloudhadoop”, The length of the string is 11....


Golang Example - Calculate Sum of digits of a integer number

December 18, 2018 ·  3 min read

In this post, You will learn different ways to addition of digits of a number in Golanguage Using Iterative Function Using Recursive Function Sum of digits of a number is to retrieve each digit of a number and add these numbers to result. For example, if given number is 154, The sum of digits of a number is 1+5+4=10. To understand this example, You should have following features in Go language...


Golang Example - Find Factorial of a Number

December 18, 2018 ·  3 min read

This blog post covers two programs to calculate factorial of a number Using Recursion function Using Iterative Function Factorial of a number n is called n! which is equal to product of all integers less than or equal to number n. This will be always calculated for positive numbers and factorial of negative numbers not exists. Factorial of a number=0 is 1. For example Factorial of 5 is equal to 5!...


Golang Example - Check if a number/integer is positive or negative

December 18, 2018 ·  2 min read

In this Example, you will learn programs to check number is positive or negative, First is using if else statement. Second is using standard library Math Signbit function. Positive number are whole number which are greater than zero ie 1,2,3… Negative numbers are number which are lesser than zero , -1,-2 Each positive number has a corresponding negative number To understanding the below programs, You have following features understanding in Go Language....


Golang Example - Print values of Array or slice

December 18, 2018 ·  4 min read

In thsi examples, You will learn different ways to print/display array or slice elements to console in Go Language. Following programs are covered Print Array using For Loop with range Display Slice using PrintF function format Array slice console print without Squarebrackets Print Address or pointer of array Print Slice of bytes in Binary Form To understand this example, You should have following features in Go language Golang For Loop control structure Golang For Loop Range form Array/Slice Tutorials  Example program: Print an Array or slice using For loop with range In the below program, Declared slice and array with initlized values using shorthand assignment operator....


Golang Example - Program Simple arithmetic Calculator Using switch...case

December 17, 2018 ·  2 min read

This blog post covers an example for Arithmetic Simple Calculator using Switch case in Golang. To understand this example, You should have following features in Go language Golang read input from user Golang Switch case Guide Golang Operators Guide with examples Example program - Arthematic Calculator using switch case The below example is to write Simple Calculator which supports Arthematic Operators like Add, Subtract, Multiply, Modulus, Division First Read the input numbers from user keyboard console, stored in variable number1 and number2....


Golang Example - Print/Display Lower/Upper Characters using rune and ASCII

December 17, 2018 ·  2 min read

This post covers two programs, the First program is to print lowercase a to z using for loop, the Second program is to display uppercase A to Z using for loop. To understand this example, You should have following features in Go language Golang For Loop control structure Golang For Loop Range form Golang Rune Datatype Beginner Guide Like other programming languages, There is no specific data type for Character representation....


Golang Example - Program to count number of digits in an integer

December 17, 2018 ·  3 min read

This example covers two programs to count the number of digits in an integer, the first program is using the iterative function, the Second program is using the Recursive function. To understand this example, You should have following features in Go language Golang For Loop control structure Golang For Loop Range form Golang read input from user Golang Recursion Function Guide Both programs read an integer value from a user keyboard, find the number of digits....


Golang Example - Program to find Smallest/Minimum number of array or slice

December 17, 2018 ·  2 min read

In this examples, You will learn how to find the minimum/smallest element of an array or slice from input from the user in Go Language To understanding the below programs, You have following features understanding in Go Language. Golang For Loop control structure Golang For Loop Range form Golang read input from user Array/Slice Tutorials  The algorithm for this program is as follows At first, the starting element of an array assumed as the smallest element will compare with other elements if elements are smaller than other elements, It will be a new smaller element, This sequence of steps continues execution until all elements are traversed....


Golang Example - Reverse of a number or integer

December 17, 2018 ·  3 min read

In this program, You will see a three program First is to reverse of a number or integer, the second program is the reverse number entered by user , thrid is reverse number using a recursive function in Go Language. To understanding the below programs, You have following features understanding in Go Language. Golang For Loop control structure Golang For Loop Range form Golang read input from user Array/Slice Tutorials Following is a sequence of steps...


Golang Example - Program to find larger/Maximum number of array or slice

December 17, 2018 ·  2 min read

In this blog post, We are going to learn to Find larger/maximum number of array or slice, reading input fro an user array or slice holds the collection of elements. The array is fixed in size, Slice is dynamic in nature. Golang program is to find the maximum or largest element in an array or slice. The logic of the below program, Initially, Array first element will be assumed as the largest element, compared with other elements, if elements are larger than other elements, It becomes a new larger element, The process continues execution until all elements are finished...


Golang Example - Program to check Largest,Smallet of three numbers

December 17, 2018 ·  2 min read

This post covers two programs, the First program to check largest of three numbers, the second program is to check the smallest of three numbers. To understand this programs, You should have understood the following features if else statements Read input from user Example Program to check largest/biggest of three numbers using if else statement In the below program, Read the three input numbers from the user using Scanln function and stored in number1,numer2,number3 variables...


Golang Example - Program to check number is prime number or not

December 16, 2018 ·  3 min read

This post covers the three programs to check Prime numbers, One is prime number check for a fixed number, Second is to check prime number read input from user console, Third to check prime number check for bigint types. The prime number in mathematics is a whole or positive number greater than 1 which divides itself and one For example, Number can be divided with remainder is zero. number 19 can be only divided by 19 or 1 only....


Golang example - program to sum the elements of an array/slice

December 16, 2018 ·  3 min read

This post covers sum of elements of an array/slice using below approaches sum array elements using for range form using variadic Functions Sum of elements entered by user input To understanding the below programs, You have following features understanding in Go Language. Golang functions guide Golang For Loop control structure Golang For Loop Range form Golang read input from user Array/Slice Tutorials  Example program Sum of array elements using for loop range package main import ( "fmt" ) func sum(array []int) int { result := 0 for _, v := range array { result += v } return result } func main() { numb := []int{1, 2, 3, 4, 5} fmt....


Golang example - Program to calculate Sum of natural numbers

December 16, 2018 ·  3 min read

This post we will cover three programs to find the sum of natural numbers Sum of first n natural numbers entered by the user Sum of first n natural numbers using for loop Sum of first n natural numbers Recursive function Natural numbers are positive integers or whole numbers which starts from 0,1, 2 …. n. These also called nonpositive numbers. This post is about calculating the sum of natural numbers from 1 to n where n is read from console by the user....


Golang Program - Print value by reading user input from console

December 14, 2018 ·  3 min read

In this blog post, input data can be read from the console in the may ways in Go language read input values using the scan function read multiple input values from console read user input line by line using stdin stream Example to read user input using the scan function package main import ( "fmt" ) func main() { //reading an string var name string fmt.Print("What is your Name?...


Golang Example - Program to check Leap year or not

December 14, 2018 ·  2 min read

In this blog post, We will write a program to check a given a year is a leap year or not Leap year is a year which meets following conditions if the year is divisible by 4, check step 2, else go to step 5 if the year is divisible by 100, check step 3 else go to step 4 if the year is divisible by 400, check step 4, else go to step 5 Then the year is lear year which has 366 days This is not leap year which has 365 days Example program to check given year is a leap year or not The following features are used in go language...


Golang Example - Check alphabet is Vowel or consonant

December 14, 2018 ·  2 min read

In this example, We will learn below programs. how to check alphabet is vowel or consonant using if-else and switch case examples and Count of vowels in a String. the vowel is called for a character if Character contains any of a, e, i, o, u characters Please have a look of below golang features before understanding this programs Switch case Guide If else statement rune data type Example program to check alphabet is Vowel or consonant using if else statement package main import ( "fmt" ) func isVowel(character rune) { if character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u' { fmt....


Golang Example - 2 ways to find swap two numbers/variables

December 13, 2018 ·  2 min read

In this post, This convers 2 ways to swap two numbers or variables in Golang. First one is to swap variables in temporary variable, another one is not using temporary variable. Example 1: Swap two values/numbers using a temporary variable package main import ( "fmt" ) func main() { number1, number2 := 12, 30 fmt.Println("Before Swap process") fmt.Println("Number1:", number1) fmt.Println("Number2:", number2) // number1 is assigned to temporary variable temporary := number1 // number1 is assigned to number2 variable number1 = number2 // temporary is assigned to number2 number2 = temporary fmt....


Go Example - Program to check string contains Alphabetic,numeric and special characters

December 13, 2018 ·  2 min read

Golang String characters The string is a group of characters enclosed in double quotes. alphabetic characters - each character contains a letter from lowercase - a to z and uppercase - A to Z. alphanumeric characters - contain alphabetic and numeric characters. Special characters - a character are like %,# ..etc with excluding alphabetic and numeric characters. This post, You will learn the following things in GoLang check String contains alphabetic check String contains alphabetic using a regular expression check String contains alphanumeric and special characters Example 1: How to check if a string contains alphabetic characters  String characters are iterated using for each loop....


Golang Example program to find quotient and remainder of a integers

December 13, 2018 ·  2 min read

In this example program, We will find quotient and remainder from the given numerator(dividend) and denominator(divisor) using modulus and division operator in Golang. The quotient is a result of the division operator in mathematics. In golang division operator / is used and applied to integers. the remainder is a result of modulus operator in mathematics. % symbol is defined in Golang. Example: Find Quotient and Remainder The below example explains about golang arithmetic operators...


Golang Example - Program to check Character is alphabetic or not

December 13, 2018 ·  2 min read

In this Example, You will learn programs how to check whether the character is alphabetic or not in go language using if else statement and switch case statement  Alphabetic characters are characters English letters in lower and upper case. Special characters are not allowed. Characters in go language are represented in rune data type which contains ASCII code value from 0 to 127. Please have a look of below golang features to have an understanding of this program better...


Golang Example - Program to Check ASCII Value of a character

December 13, 2018 ·  2 min read

In this example, you will learn below two programs in go language How to display ASCII value of a character in Go language.  Convert/cast Character to/from ASCII in golang ASCII is a code which contains 128 characters with integer values from 0 to 127. It can be stored in 8-bit types ie byte In Go languages, There is no character type, but it can be represented in rune data type....


Golang example - program to multiply two numbers

December 13, 2018 ·  2 min read

In this blog post, you are going to learn below things Multiply two integers  Multiply two floating numbers Multiply integer and floating numbers  Example1 program to Multiply two integers package main import ( "fmt" ) func main() { var number1, number2 int number1 = 5 number2 = 6 result := number1 * number2 fmt.Printf("Multiply result is %d\n", result) } Output is Multiply result is 30 Example2 program to Multiply two floating numbers package main import ( "fmt" ) func main() { var number1, number2 float64 number1 = 5....


Golang example - Program to Calculate average using Array/slice of numbers

December 13, 2018 ·  2 min read

In this blog post, You will learn two programs for finding average of array/slice numbers. First program to find avrage of fixed array of numbers The second program to read the input of values from a user via command line calculates the average. Following are golang features are required to under this programs Slice Guide For Loop Basics For Loop in range form Example program to check average of an array of numbers First Array or integers is declared with inline assignment of the values...


golang example - program to check number/integer even or odd

December 13, 2018 ·  2 min read

In this blog post, we will learn two programs The first program is how to check input number is even or odd.the second program is how to check given array or slice of number for even or odd numbers. Even number is a number divisible to 2 is zero that means the number is even if operation modulus operator divisible by 2 is remainder=0 Example to check Number is even or odd In the below program....


Golang Example programs

December 12, 2018 ·  1 min read

Go is a Static typed popular programming language. To learn a new programming language, We must write a practical example by making use of features. This is an index page for all golang features like control statements -loops, if else, datatypes, data structures, classes, Conversions of one datatype to others,and objects All the programs and examples are compiled and tested and given output. if you are new to go language, want to learn golang before working on this program, then have a look Golang Tutorials....


Golang examples - Program to add/sum of two numbers or integers

December 12, 2018 ·  2 min read

In this program, we have two programs to add two numbers. The First program, We will store the numbers and the addition of two numbers. The second program, take the two numbers from the user and return the sum of two numbers. Example: Sum of two numbers  In this program, variables are declared and did inline assignment statements. This is one way of declaring multiple variables of the same type in golang...


Golang Example - Convert(Cast) String to Float and Float to String

December 12, 2018 ·  3 min read

This post covers how to convert(cast) String type to float type or float type to String with an example. Golang strconv package The string is a group of characters referenced by a variable. A float is a numeric number that stores set of all IEEE-754 64-bit floating-point numbers. Both are of different types, Automatic conversions will not occur. The developer needs to write a code to handle this. Golang provides standard inbuilt package strconv to do string conversions to other types....


Golang Recursion - Recursive function with examples

December 11, 2018 ·  3 min read

In this blog post, we are going to learn Recursive functions in golang with examples. golang recursive function Recursion is general programming code process in which method or function calls itself continuously. Go Language support recursion using functions. In Golang, function call itself is called recursive function. Using this technique, It allows code simple but complex to understand the code.  Important key points of recursion function. Function called inside the same function It is always good to specify an exit condition in the recursive function It reduces unnecessary function calls and code lines  Disadvantages with recursion is code is logical and difficult to debug and inspect the code Syntax // function declaration func recursefunction(){ //Code statements recursefunction();//function call itself } func main(){ recursefunction() // Initialize first normal call } In the above syntax, the recursive function is being called inside the same function....


Golang Example - strconv ParseFloat function guide

December 10, 2018 ·  3 min read

This blog post covers package strconv ParseFloat Function with examples in the Go Language. golang strconv ParseFloat function strconv is a standard inbuilt package in go language that provides various function implementations for converting a string to types into an int, float, boolean etc.. String to float is a common task of a programmer during development ParseFloat is an inbuilt function, converts a String value to a floating number...


golang examples - Hostname and IP address programs code

December 4, 2018 ·  3 min read

Golang hostname The hostname is a label assigned to a machine which is connected in Network of machines. Golang standard package net provides functions related to TCP/IP, UDP and DNS related networking related functionalities The following are various examples related to the hostname and Ip addresses in Go Language. Get Hostname of the System environment It is always good to know the hostname of the environment where the go program is running....


Go By Examples - Map types Advanced Programs

November 28, 2018 ·  7 min read

This post covers Golang Map types tutorials with examples In my previous post, Covered Map guide in Golang Following are the Map type examples in Go Language Sort a Map by key or values The map is ordered data structure of key-value pairs. To sort map, We have to write a custom to handle this, For example, we have a map of string key and int values. Printing the map returns map data in random order, the order is not guaranteed....


GoLang Examples - Convert Int to String type tutorials

November 25, 2018 ·  3 min read

In this blog post, We are going to learn how String conversion from Int type in go language with examples. Golang cast int, String  In Any programming language, Anything user entered in text fields always considered as String and saved to Database as Integer. you check my other post on Convert String to Int type. In some cases, we need to convert this Integer to String. For example, the integer contains numbers 167 and will convert this int to string as “167”....


Golang Example - strconv FormatInt Function Guide

November 25, 2018 ·  3 min read

In this blog post, We are going to learn strconv FormatInt Function with examples in the Go Language. golang strconv FormatInt function strconv is a standard package in go language that provides various function implementations for converting a string to types into an int, float, boolean etc.. FormatInt is one of important function that used to convert Integer type to String type. You can check official documentation is here Here is the syntax of this function...


GoLang Examples - Convert String to Int types with examples

November 21, 2018 ·  5 min read

This article three ways to Convert String to Integer in Go Language. Golang cast String int usually when we want to perform mathematical calculations on strings which contains text. For example, This will be received an input from a user on a form in web applications, If the user enters any value in the text field. For example, the string contains numbers “134” and will convert this string to int....


Golang Example - strconv ParseInt Function explained

November 20, 2018 ·  3 min read

In this blog post, We are going to learn strconv ParseInt Function with examples in the Go Language. strconv ParseInt Function strconv package provides functions for converting String to or from different data types. PaseInt() is one of the functions used to convert String to Integer types and used for Number conversions. You can get official documentation from here Syntax Here is a signature of ParseInt example func ParseInt(s string, radix/base int, bitSize int) (i int64, err error) Arguments List -...