java大小寫字母相互轉換
阿新 • • 發佈:2018-11-22
**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; } }**