1. 程式人生 > >java大小寫字母相互轉換

java大小寫字母相互轉換

**package com.isof.dom.practice;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MyClass {
	public static void main(String [] args){
		String le = new String(args[0]);
		MyClass MM = new MyClass();
		String b =MM.aiphabetRel(le);
		System.out.println(b);
		}
	public String aiphabetRel(String a){
		Pattern pa =Pattern.compile("[A-z]");
		Matcher M = pa.matcher(a);
		Pattern p =Pattern.compile("[A-Z]");
		Matcher A = p.matcher(a);
		if(M.find()){
			if(A.find()){
				a=a.toLowerCase();
			}else{
				a=a.toUpperCase();
			}
			
		}else{
			a="請輸入字母";
		}
		return a;
		
	}

}**