需求:将小写字母转换为大写字母

实现方式:

  1. 使用String的toUpperCase() 方法
  2. 使用 char charAt(int index)方法,获取指定下标index位置上的字符

代码实现

public class Convert {
	public static void main(String[] args) {
		String s1="adhsvf";
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<s1.length();i++) {
			char temp=s1.charAt(i);
			if (temp>='a' && temp<='z') {
				char cc=(char)(temp-32);
				sb.append(cc);
			}else 
				sb.append(temp);
		}
		System.out.println(sb);
	}
}

运行结果

java 把小写字母转大写 java小写字母转化为大写_System