1. 請(qǐng)寫一個(gè)字符串轉(zhuǎn)成駝峰的方法?
例如:border-bottom-color -> borderBottomColor
2. 查找字符串中出現(xiàn)最多的字符和個(gè)數(shù),?
如 sdsdsddssssssdd -> 字符最多的是s,,出現(xiàn)惡9次
3. 如何給字符串加千分符,?
如:18239423 -> 18,239,423
參考答案:
public class UC {
static void first() {
String s = “border-bottom-color”;
String[] array = s.split(“-”);
StringBuffer sb = new StringBuffer();
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(array[i].substring(0, 1).toUpperCase()
+ array[i].substring(1, array[i].length()));
}
System.out.println(“border-bottom-color -> ” + sb.toString());
}
static void second() {
String param = “sdjksfssscfssdd”;
int history = 0;
char result = ‘a(chǎn)’;
for (int i = 0; i < param.length(); i++) {
char tc = param.charAt(i);
int pos = param.indexOf(tc);
int count = 0;
while (pos != -1) {
count++;
param = param.substring(pos + 1);
pos = param.indexOf(tc);
}
if (count > history) {
history = count;
result = tc;
}
}
System.out.println(“出現(xiàn)次數(shù)最多的字符是:” + result + “,總共出現(xiàn)了” + history + “次”);
}
static void three() {
StringBuffer temp = new StringBuffer();
temp.append(“3562123761″);
temp.reverse();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < temp.length(); i = i + 3) {
if ((i + 3) < temp.length()) {
sb.append(temp.substring(i, i + 3) + “,”);
} else {
sb.append(temp.substring(i));
}
}
System.out.println(“3562123761 -> ” + sb.reverse().toString());
}
public static void main(String[] args) {
// substring(num),截取num及num后面的字符串,;substring(start,end),,截取start及end之間的數(shù)據(jù)
first();
second();
three();
}
}
|