java字符串大小寫轉換

public class DaxiaoxieTrans {
	public static void main(String[] args) {
		test();

	}

	private static void test() {
		// TODO Auto-generated method stub
		System.out.println("請輸入一連串字符串:");
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		char[] ch = str.toCharArray();
		for (int i = 0; i < ch.length; i++) {

			if (ch[i] > 'a' && ch[i] < 'z') {
				ch[i] -= 32;
			} else if (ch[i] > 'A' && ch[i] < 'Z') {
				ch[i] += 32;
			}

		}
		for (int i = 0; i < ch.length; i++) {
			System.out.print(ch[i]);
		}
	}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章