华为机试题: 将数组中的字符串按指定长度重新分割(java)
来源:互联网 发布:java 参数 编辑:程序博客网 时间:2024/06/01 10:15
描述:
请实现接口 convertStringArray。
输入一个字符串数组, 请按指定长度iInputLenth拆分数组中的每个字符串,输出到新的字符串数组中。长度不是iInputLenth整数倍的字符串请在后面补数字0。空字符串不处理,遇到空字符串则表示该数组结束。
/*
功能:请编写一个函数,输入为一个字符串数组,
请按指定长度iInputLenth拆分数组中的每个字符串,输出到新的字符串数组中。长度不是iInputLenth整数倍的字符串请在后面补数字0。
空字符串不处理,遇到空字符串则表示数组结束,函数返回。
输入:
String inputStrArray 字符串数组指针 字符串个数最大为50,字符串长度最大255
int iInputLenth 指定的分割长度 iInputLenth>=1 && <=32 <><=32 <><=32 <>
返回:字符串数组指针
示例 按长度8拆分
输入: abc
12345789
返回: abc00000
12345678
90000000
*/
public static String[] convertStringArray(String[] inputStrArray, int iInputLenth)
{
return null;
}
package huawei;import java.util.Vector;public final class Demo {/*功能:请编写一个函数,输入为一个字符串数组,请按指定长度iInputLenth拆分数组中的每个字符串,输出到新的字符串数组中。长度不是iInputLenth整数倍的字符串请在后面补数字0。空字符串不处理,遇到空字符串则表示数组结束,函数返回。输入: String inputStrArray 字符串数组指针 字符串个数最大为50,字符串长度最大255 int iInputLenth 指定的分割长度 iInputLenth>=1 && <=32 返回:字符串数组指针 示例 按长度8拆分输入: abc 12345789 返回: abc00000 12345678 90000000*/public static String[] convertStringArray(String[] inputStrArray, int iInputLenth){/*入参判断*/if (iInputLenth < 1 || iInputLenth > 32){return null;}Vector<String> vec = new Vector<String>();//保存生成的字符串for(int i = 0; i < inputStrArray.length; i++){/*把这个字符串取出来*/String str = inputStrArray[i];char[] src = str.toCharArray();/*这个字符串不为空*/if(str.length() > 0){int curIndex = 0;for(; (curIndex + iInputLenth) < str.length(); curIndex += iInputLenth){/*新建一个StringBuilder对象*/StringBuilder temp = new StringBuilder();for(int j = 0; j < iInputLenth; j ++){temp.append(src[curIndex + j]);}vec.add(temp.toString());}int count = 0;StringBuilder temp1 = new StringBuilder();for(; curIndex < str.length(); curIndex++){temp1.append(src[curIndex]);count++;}/*补0*/for(; count < iInputLenth; count++){temp1.append('0');}vec.add(temp1.toString());}}if(vec.size() > 0){String[] ret = new String[vec.size()];ret= vec.toArray(ret);return ret;} return null;}}
0 0
- 华为机试题: 将数组中的字符串按指定长度重新分割(java)
- 上机题目(中级)- 将数组中的字符串按指定长度重新分割 (Java)
- 2016华为机试题:字符串按指定长度分割
- Java将字符串按指定长度分割
- 华为校招2016.09机试 第1题: 字符串按指定长度重新分割
- 2017年,华为机试题目 《字符串按指定重新分配》 --Java实现
- 华为机试题: 字符串分割
- 根据字符串中的指定子字符串将原字符串分割成字符串数组
- 将指定字符串分割成字符数组
- 用正则表达式按指定长度分割字符串(C#)
- 将字符串按照指定的长度进行分割(一个中文视为两个字符)
- (java)华为机试题:字符串变换
- 华为机试题:将十六进制字符串形式内容转为内存值形式(java)
- 华为机试题:将字符串间隔输出
- Java 按照指定长度分割字符串(一种是纯英文字符串,一种是英汉混合的字符串)
- java中split()方法分割字符串后数组长度问题
- 按长度分割字符串
- 将指定字符串按指定长度进行剪切
- 配置CENTOS YUM更新源
- 实现RadioGroup与Fragment的交互
- APP市场推广统计有效推广量新思路
- 遗传算法解决tsp问题
- namenode两次格式化的问题
- 华为机试题: 将数组中的字符串按指定长度重新分割(java)
- Java HashMap 核心源码解读
- maven下面编译失败,失败提示信息为:程序包com.sun.image.codec.jpeg不存在
- CNTK学习笔记(一)
- iOS-KVC/KVO学习
- 自定义日志打印
- 【线扫描填充算法】用例过程图解
- 一个APP终于能调用外部library了
- we must recreate the epoll after fork