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
16 Sep 2026
Cursor IDE for Golang: Setup .cursorrules, Composer, and Agent Mode
27 mnt
Read
Go
15 Sep 2026
Claude Code for Golang: Setup, Best Practices, and the Optimal Workflow
25 mnt
Read
Go
14 Sep 2026
Decision Framework for AI Coding Tools in Golang 2026: Choose the Right One
27 mnt
Read
Go
11 Sep 2026
Benchmark AI Coding Tools for Golang 2026: Claude vs Cursor vs Copilot vs Kiro
27 mnt
Read