15 Apr 2021
·
2 min read
·Article 10 / 119
GoHow to Determine Consonant Vowels in Golang
IH
Ihsan Arif
Writer at Santekno · Backend Engineer
Introduction
Determining consonant vowels here will be divided into several examples. Later we will know better which processes will be carried out sequentially. What we already know is that the vowel characters are a,i,u,e,o and this will be a condition in the program later.
The program determines vowels and consonants using if..else
1package main
2
3import (
4 "fmt"
5)
6
7func isVokal(character rune) {
8 if character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u' {
9 fmt.Printf(" %c adalah vokal\n", character)
10 } else {
11 fmt.Printf(" %c adalah konsonan\n", character)
12 }
13
14}
15func main() {
16 isVowel('a') // vokal
17 isVowel('b') // konsonan
18} The result is below
1a adalah vokal
2b adalah konsonanThe program determines vowels and consonants using switch case
1package main
2
3import (
4 "fmt"
5)
6
7func isVokal(character rune) {
8 switch character {
9 case 'a', 'e', 'i', 'o', 'u':
10 fmt.Printf(" %c adalah vokal\n", character)
11 default:
12 fmt.Printf(" %c adalah konsonan\n", character)
13 }
14}
15func main() {
16 isVowel('e') // vokal
17 isVowel('g') // konsonan
18} 1e adalah vokal
2g adalah konsonanExplanation
In this program, the user is asked to enter the characters stored in the variable c. Then, this character is checked to see if it is one of these ten characters, namely A, a, I, i, U, u, E, e, O and o using the logical OR operator ||. If one of the ten characters in the alphabet is vowel then that alphabet is a consonant.
(Bonus) The program counts vowels in sentences
1package main
2
3import (
4 "fmt"
5)
6
7func main() {
8 str := "santekno"
9 count := 0
10 for _, ch := range str {
11 switch ch {
12 case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U':
13 count++
14 }
15 }
16 fmt.Printf("kalimat %s mengandung vokal sebanyak: %d\n", str, count)
17
18} The result is below
1kalimat santeno mengandung vokal sebanyak: 3Related Articles
Go
14 Aug 2026
The .specify Folder Structure: Anatomy of the Generated Output
13 mnt
Read
Go
13 Aug 2026
Installing the specify CLI: Persistent vs One-time Setup
10 mnt
Read
Go
12 Aug 2026
What Is GitHub Spec Kit and Where It Fits in the SDD Workflow
13 mnt
Read
Go
11 Aug 2026
After SDD Golang: Deeper Tools and the Future of AI-Driven Development
12 mnt
Read