Home Development API Go – Reversing a String

Go – Reversing a String

202
0


As a little example of basic Golang, I wrote a little app that takes user input and reverses the word as output:

package main

import "fmt"

var userInput 

func main() {
   reverseWord()
}

func reverseWord() {

   fmt.Println("Input a word> ")
   fmt.Scan(&userInput)
   var word_length int = len(userInput)
   for i := word_length; i > 0; i-- {
      fmt.Print(userInput[(i - 1):i])
   }
}

Leave your vote

0 points

Upvote
Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%


I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It’s my hope that it gives hope to any and all who are self-taught.



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here