用go语言实现,判断一个程序是否为小写字母,如果是,就转换成大写字母,否则,不转换

  这种题目相对简单,用C语言实现很好理解。

//用C语言实现:判断一个程序是否为小写字母,如果是,就转换成大写字母,否则,不转换
#include<iostream>

using namespace std;

int main(void) {
    char c;

    cout << "请输入一个字符: " << endl;
    cin >> c;

    if (c >= 'a' && c <= 'z') {  //判断是否为小写字母,。,,,利用ASCLL码表
        c = c - 32;   //转换成大写
    }
    else if (c >= 'A' && c <= 'Z') { //判断是否为大写字母
        c = c + 32;   //转换成小写
    }

    cout << c << endl;

   
    system("pause");
    return 0;
}

用go语言实现的两种方法

package main

import(
	"fmt"
)

func main(){
	var x string
	fmt.Println("请输入字符:")
	fmt.Scanln(&x)
	t:= snfn(x)
	fmt.Println(t)
}

func snfn(x string)string{
	c := rune(x[0])
	c -= 32
	return string(c)
}

package main

import "fmt"

func main(){
	for {
		var x string
		fmt.Println("请输入一个字符:")
		fmt.Scanln(&x)

		t := converSion(x)
		fmt.Println(t)
	}
}

func converSion(a string) string  {
	var ay = []string{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
	var ay2 = []string{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
	for k, v := range ay{
		if v == a{
			a = ay2[k]
		}
	}
	return a
}

//还可以使用strings包中的
//strings.ToLower()
//strings.ToTitle()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值