1.將"goOd gooD stUdy dAy dAy up"每個單詞的首字母轉換成大寫其餘還是小寫字母(最好理解版)
阿新 • • 發佈:2019-01-23
個人覺得這個解法最簡單而且好理解:
public class ToUperCase { public static void main(String[] args) { String str = "goOd gooD stUdy dAy dAy up"; //切割儲存在陣列,再進行轉換 String[] strings = str.split(" "); ArrayList<String> list = new ArrayList<>(); for (String s : strings){ String lowerCase = s.toLowerCase(); list.add(lowerCase); } for (String s : list){ String substring = s.replace(s.substring(0,1),s.substring(0,1).toUpperCase()); System.out.print(substring+" "); } }