字符串中大小写转换小例

package week11_2;

/**
 * 转换大小写
 * @author Guozhu Zhu
 * @date 2019/5/7
 * @version 1.0
 *
 */
public class Demo01 {
	
	/* ========== Test ========== */
	public static void main(String[] args) {
		String str = "abcDE";
		String res01 = toLowwerCase(str);
		String res02 = toUpperCase(str);
		System.out.println(res01);
		System.out.println(res02);
	}
	
	//转化成小写
	public static String toLowwerCase(String str) {
		char[] ch = str.toCharArray();
		for (int i = 0; i < str.length(); i++) {
			if (ch[i] >= 'A' && ch[i] <= 'Z') {
				ch[i] = (char)(ch[i]+'a'-'A');
			}
		}
		return new String(ch);
	}
	
	//转化成大写
	public static String toUpperCase(String str) {
		char[] ch = str.toCharArray();
		for (int i = 0; i < str.length(); i++) {
			if (ch[i] >= 'a' && ch[i] <= 'z') {
				ch[i] = (char)(ch[i]+'A'-'a');
			}
		}
		return new String(ch);
	}

}

字符串中大小写转换小例

相关文章: