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
06 Nov 2026
Golang E-Commerce OpenAPI Contract: API Documentation from an SDD Spec
22 mnt
Read
Go
05 Nov 2026
Golang E-Commerce Architecture Design: Clean Architecture + Multi-Service
24 mnt
Read
Go
04 Nov 2026
Build E-commerce Golang from Scratch: From Business Needs to SDD Spec
23 mnt
Read
Go
03 Nov 2026
Bridge to Topic 5: AI-Powered E-Commerce Golang — Preview and Preparation
21 mnt
Read