打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
UC 优视科技字符串算法面试题

1. 请写一个字符串转成驼峰的方法?

例如:border-bottom-color -> borderBottomColor

2. 查找字符串中出现最多的字符和个数?

如 sdsdsddssssssdd -> 字符最多的是s,出现恶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’;
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(“出现次数最多的字符是:” + result + “,总共出现了” + 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之间的数据
first();
second();
three();

}

}

 

 

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
java反射
常用java字符串操作函数(转)
【Java字符串】字符串虽简单,但这些你不一定知道【小白一定要注意】
16进制字符串与byte数组互转
StringBuffer类的截取功能
JAVA版微信支付V3-完全版
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服