711
技術社區[雲棲]
JAVA麵試題-STRINGBUFFER倒序輸出、正則將首字母大寫
package com.zzk.test; //將This is a test倒著輸出tset a si sihT(用StringBuffer) public class Test{ public static void main(String[] args) { StringBuffer s=new StringBuffer("This is a test"); System.out.println(s.reverse()); } }
輸出:
tset a si sihT
package com.zzk.test; //將this is a test轉化為This Is A Test public class Test { public static void main(String[] args) { String s="today is nice hahaha"; String arr[]=s.trim().split("\\s+"); if(s.length()>0) for(int i=0;i<arr.length;i++) { arr[i]=Character.toUpperCase(arr[i].charAt(0))+arr[i].substring(1); System.out.print(arr[i]+" "); } } }
輸出:
Today Is Nice Hahaha
最後更新:2017-04-02 06:52:11