一.题目描述:
【问题描述】
输入一个由小写英文字母组成的字符串,请将其中的元音字母(a, e, i, o, u)转换成大写,其它字母仍然保持小写。
【输入格式】
输入一行包含一个字符串。
【输出格式】
输出转换后的字符串。
二.代码:
import java.util.Scanner;
public class test1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s = sc.next();
char []ch = s.toCharArray();
for(int i=0;i<ch.length;i++){
if(ch[i]=='a'){
ch[i]='A';
}
if(ch[i]=='e'){
ch[i]='E';
}
if(ch[i]=='i'){
ch[i]='I';
}
if(ch[i]=='o'){
ch[i]='O';
}
if(ch[i]=='u'){
ch[i]='U';
}
}
System.out.println(ch);//输入:lanqiao 输出:lAnqIAO
}
}
三.知识点:
大写字母与小写字母之间的差值为 32
小写字母转换为大写字母的方法就是将小写字母的 ASCII 码值减去 32
大写字母转换为小写字母的方法就是将大写字母的 ASCII 码值加上 32