Go Program to Check Character is an Uppercase

Write a Go Program to check whether the character is Uppercase or not. The unicode IsUpper finds the Rune is the Uppercase character. We used this IsUpper function in the If else condition (if unicode.IsUpper(upch)) to find the given character is Uppercase or not.

package main

import (
    "bufio"
    "fmt"
    "os"
    "unicode"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter Character to Check Uppercase = ")
    upch, _, _ := reader.ReadRune()

    if unicode.IsUpper(upch) {
        fmt.Println("You have Entered the Uppercase Character")
    } else {
        fmt.Println("The entered Character is Not the Uppercase")
    }
}
Go Program to Check Character in an Uppercase 1

Go Program to Check Character is an Uppercase or Not

In this Go Uppercase character example, we convert the given byte to Rune (if unicode.IsUpper(rune(upch))) and then use the IsUpper function.

package main

import (
    "bufio"
    "fmt"
    "os"
    "unicode"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter Character to Check Uppercase = ")
    upch, _ := reader.ReadByte()

    if unicode.IsUpper(rune(upch)) {
        fmt.Println("You have Entered the Uppercase Character")
    } else {
        fmt.Println("The entered Character is Not the Uppercase")
    }
}
SureshMac:GoExamples suresh$ go run charIsUpper2.go
Enter Character to Check Uppercase = o
The entered Character is Not the Uppercase
SureshMac:GoExamples suresh$ go run charIsUpper2.go
Enter Character to Check Uppercase = M
You have Entered the Uppercase Character

In this Golang example, We used the If condition (if upch >= ‘A’ && upch <= ‘Z’) to check the character is between A and Z, and if true, it is an Uppercase.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter Character to Check Uppercase = ")
    upch, _ := reader.ReadByte()

    if upch >= 'A' && upch <= 'Z' {
        fmt.Println("You have Entered the Uppercase Character")
    } else {
        fmt.Println("The entered Character is Not the Uppercase")
    }
}
SureshMac:GoExamples suresh$ go run charIsUpper3.go
Enter Character to Check Uppercase = A
You have Entered the Uppercase Character
SureshMac:GoExamples suresh$ go run charIsUpper3.go
Enter Character to Check Uppercase = k
The entered Character is Not the Uppercase

This Golang Program uses the ASCII codes (if upch >= 97 && upch <= 122) to find the character is Uppercase or not.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter Character to Check Uppercase = ")
    upch, _ := reader.ReadByte()

    if upch >= 97 && upch <= 122 {
        fmt.Println("You have Entered the Lowercase Character")
    } else {
        fmt.Println("The entered Character is the Uppercase")
    }
}
SureshMac:GoExamples suresh$ go run charIsUpper4.go
Enter Character to Check Uppercase = B
The entered Character is the Uppercase
SureshMac:GoExamples suresh$ go run charIsUpper4.go
Enter Character to Check Uppercase = z
You have Entered the Lowercase Character