Created
April 23, 2022 17:12
-
-
Save TheBraveByte/6f46b0b2c68bd8c55ab31ed85441e590 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
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") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment