输出
大写字母
例
输入
whaT
输出
WHAT
#include<stdio.h>
int main()
{
char str[256];
char* p = str;
gets(str);
while (*p!='\0')
{
if (*p >= 'a' && *p <= 'z')
*p -= 'a' - 'A';
p++;
}
printf("%s", str);
return 0;
}
public static void main(String[] args) {
dxx();//调用dxx方法
}
public static void dxx(){//dxx方法
Scanner s = new Scanner(System.in);//new一个输入对象
System.out.println("请输入要进行大小写转换的字母:");
String sr = s.next();//让用户输入
char [] c =sr.toCharArray();//把用户输入的字符串转化为char类型数组,就是把每一个单独抽出来,放到一个char类型的数组里面
for (int i = 0; i <c.length ; i++) {
if (Character.isUpperCase(c[i])){//通过for循环判断每一个索引的字母是否大写
c[i]+=32;//大写字母ASCLL编码比小写的小32
}else{
c[i]-=32;//反之如果是小写加32
}
}
for (int i = 0; i < c.length; i++) {
System.out.print(c[i]);//把数组遍历打印出来
}
}
按你说的把输入的字母全部修改成大写字母
如下:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
char a[256];
int i = 0;
scanf("%s", a); //读取
while (a[i] != '\0')
{
if (a[i]>='a' && a[i]<='z')
printf("%c", a[i]-32);
else
printf("%c", a[i]);
i++;
}
return 0;
}