-
Notifications
You must be signed in to change notification settings - Fork 84
Latihan noverry-ambo Golang Basic #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| Soal 1 | ||
| Buat program `palindrome` menggunakan golang | ||
|
|
||
| $ go main.go | ||
| $ madam | ||
|
|
||
| output | ||
| true | ||
|
|
||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import "fmt" | ||
|
|
||
| func isPalindrome(input string) bool { | ||
|
|
||
| for i := 0; i < len(input)/2; i++ { | ||
| if input[i] != input[len(input)-i-1] { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| func main() { | ||
|
|
||
| var str string | ||
|
|
||
| fmt.Print("Cek Palindrome : ") | ||
| fmt.Scan(&str) | ||
|
|
||
| result := isPalindrome(str) | ||
|
|
||
| if result == true { | ||
| fmt.Println("true") | ||
| } else { | ||
| fmt.Println("false") | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* Soal 2 | ||
| Buat program untuk menentukan Huruf yang diinput Vokal atau Konsonan | ||
| >>> input | ||
| $ go main .go | ||
| h | ||
| >>> output | ||
| Konsonan | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import "fmt" | ||
|
|
||
| func isVocal(vocal string) string { | ||
|
|
||
| if vocal == "a" || vocal == "e" || vocal == "i" || vocal == "o" || vocal == "u" { | ||
| vocal = "Vokal" | ||
| } else { | ||
| vocal = "Konsonan" | ||
| } | ||
|
|
||
| return vocal | ||
| } | ||
|
|
||
| func main() { | ||
| var vocal string | ||
| fmt.Print("Masukkan huruf : ") | ||
| fmt.Scan(&vocal) | ||
|
|
||
| result := isVocal(vocal) | ||
|
|
||
| if result == "Vokal" { | ||
| fmt.Println("Vokal") | ||
| } else { | ||
| fmt.Println("Konsonan") | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package main | ||
|
|
||
| func isVocal(vocal string) string { | ||
|
|
||
| if vocal == "a" || vocal == "e" || vocal == "i" || vocal == "o" || vocal == "u" { | ||
| vocal = "Vokal" | ||
| } else { | ||
| vocal = "Konsonan" | ||
| } | ||
| return vocal | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package main | ||
|
|
||
| import "testing" | ||
|
|
||
| func Test_isVocal(t *testing.T) { | ||
| type args struct { | ||
| vocal string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want string | ||
| }{ | ||
| { | ||
| name: "konsonan or vocal", | ||
| args: args{ | ||
| vocal: "madam", | ||
| }, | ||
| want: "Konsonan", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package main | ||
|
|
||
| func isPalindrome(input string) bool { | ||
|
|
||
| for i := 0; i < len(input)/2; i++ { | ||
| if input[i] != input[len(input)-i-1] { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package main | ||
|
|
||
| import "testing" | ||
|
|
||
| func Test_isPalindrome(t *testing.T) { | ||
| type args struct { | ||
| input string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "konsonan or vocal", | ||
| args: args{ | ||
| input: "madam", | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "konsonan or vocal", | ||
| args: args{ | ||
| input: "rusak", | ||
| }, | ||
| want: false, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bisa ditambahkan buat terlebih dahulu input-nya menjadi uppercase atw lowercase biar bisa diseragamkan