(1)字符串由多个数字字符串和空格组成,如:
    String str="99 345 8 888 55 0 -9999 30";
请编写函数sortNumStr,将字符串中数字字符串按数值大小升序排序,组成新的字符串:
    public static String sortNumStr(String numStr)
例如,以上例中的str作为参数,返回结果:
    "-9999 0 8 30 55 99 345 888"测试用例:除题目中例子外还有:
    "1"
    "2008 -2008 2000 1997 1978 2010"
    "1 0"(2)用ArrayList或LinkedList实现先进先出队列Queue。自定义class Queue。测试用例:
    依次入队三个字符串 "a" "i" "l", 出队 ,入队 "i", 出队,入队 "u" "g" "l",打印队列中的所有字符串。(3)“密码”“MAC码”等数据由于是二进制数据,在Java中只能以byte[]形式存放,
但往往需要转化成可见字符串在通讯报文(如XML)中传递。
例如,密文: byte[] password = {0x5A,0x08,0x00,0xFF,0xB2,0x33,0xDE,0xFF};
转化为字符串:"5A0800FFB233DEFF"
请编程实现方法byte2HexString完成这种转化:
    public String byte2HexString(byte[] b)
注:字符'A'的数值为0x41,字符'0'的数值为0x30测试用例:除题目中例子外还有:
    {0x00}
    {0xFF}
    {0x00 0xFF}
    {0xFF 0xFF 0x00}(4)Java中1个char类型的变量可存储任意编码的1个字符,如1个ASC码和或1个中文字符,例如:含有3个ASC和含有3个汉字字符的字符串长度是一样的:
    "1ac".length()==3;
    "你好a".length()=3;
但上述两个字符串所占的byte是不一样的,前者是3,后者是5(1个汉字2byte)。
请编写函数:
    public static String leftStr(String source, int maxByteLen)
从source中取最大maxByteLen个byte的子串。当最后一个byte恰好为一个汉字的前半个字节时,舍弃此byte。例如:
    String str="888技术服务部999";
    leftStr(str,4)=="888";
    leftStr(str,5)=="888技";
    leftStr(str,6)=="888技";
    leftStr(str,7)=="888技术";
    leftStr(str,10)=="888技术服";测试用例:除题目中例子外还有:
    "长信通0技术部88企划部999" maxByteLen分别取 0 1 2 3 4 5 6 7 8 9 13 14 15 16 17

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【damong1316】截止到2008-07-20 18:32:41的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:0                        
    结贴的百分比:0.00  %               结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    package com.qianyue.webapp.module.trade.message.mac;import java.util.HashMap;
    import java.util.Map;import antlr.ByteBuffer;import com.qianyue.security.DesCipher;public class Mac {
    public static void main(String args[]) {        
            byte[] password = {0x5A,0x08,0x00,(byte)0xFF,(byte)0xB2,0x33,(byte)0xDE,(byte)0xFF};
            System.out.println(byte2HexString(password));
            
            String template="尊敬的客户${customerName}你好!本次消费金额${amount}," +
                    "您帐户${accountNumber}上的余额为${balance}";
            Map<String, String> data = new HashMap<String, String>();
            data.put("customerName", "刘明"); 
            data.put("accountNumber", "888888888888888"); 
            data.put("balance", "$1000000000000000000000.00"); 
            data.put("amount", "$5000.00");
            System.out.println(composeMessage(template, data));
        }
        
        public static String byte2HexString(byte[] b) {
            if(b == null || b.length == 0) {
                return "";
            }
            StringBuffer sb = new StringBuffer(b.length * 2);
            for(int i = 0; i < b.length; i++) {
                sb.append(String.format("%02X", b[i]));
            }
            return sb.toString();
        }
        
        public static String composeMessage(String template, Map<String, String> data) {
            int index = template.indexOf("${");
            if(index < 0) {
                return template;
            }
            int last = -1;
            StringBuffer sb = new StringBuffer(); 
            while(index > 0) {
                sb.append(template.substring(last + 1, index));
                last = template.indexOf("}", last + 1);
                String str = template.substring(index + 2, last);
                index = template.indexOf("${", last + 1);
                String replacement = data.get(str);
                if(replacement != null) {
                    sb.append(replacement);
                }
            }
            return sb.toString();
        }}