Last active
April 23, 2022 17:30
-
-
Save TheBraveByte/287b79eab73b994f83b245f27ed0679c to your computer and use it in GitHub Desktop.
Task 6 : 30daysOfCode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
"strings" | |
) | |
func ReadLine(reader *bufio.Reader) string { | |
str, _, err := reader.ReadLine() | |
if err == io.EOF { | |
return "" | |
} | |
return strings.TrimRight(string(str), "\r\n") | |
} | |
func EvenOddIndex() { | |
fmt.Println("Enter a string value (2<= string <=10000) : ") | |
reader := bufio.NewReader(os.Stdin) | |
str := strings.TrimSpace(ReadLine(reader)) | |
switch { | |
case len(str) == 1: | |
fmt.Print() | |
break | |
case len(str) > 1: | |
evenIndex := "" | |
oddIndex := "" | |
for i, v := range str { | |
if i%2 == 0 || i == 0 { | |
evenIndex = evenIndex + string(v) | |
} else if i%2 >= 1 { | |
oddIndex = oddIndex + string(v) | |
} | |
} | |
//fmt.Println("The characters in even index : ", evenIndex) | |
//fmt.Println("The characters in odd index : ", oddIndex) | |
fmt.Println(evenIndex, oddIndex) | |
break | |
default: | |
fmt.Println("Input value less than 1") | |
} | |
} | |
func main () { | |
EvenOddIndex("2") | |
EvenOddIndex("hackerRack") | |
EvenOddIndex("develop") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment