「已注销」 2008-11-04 23:08
浏览 198
已采纳

大家帮忙看看这到面试题

String str=”WeeciolGmmcc”
分别用for,while,switch3种循环写出程序,使程序能打印出WelcomeGmcic,
一个打印语句只能打印出一个字符

  • 写回答

4条回答 默认 最新

  • bohemia 2008-11-05 09:25
    关注

    [code="java"] String src = "WeeciolGmmcc";

        String dest= "WelcomeGmcic";
    
        //Initialize the reflection map
        Map m1 = new HashMap();
        for(int i=0; i<src.length() && i<dest.length(); i++){
            m1.put(""+src.charAt(i)+i, ""+dest.charAt(i));
        }
    
        //by for
        for(int i=0; i<src.length(); i++){
            System.out.print(m1.get(""+src.charAt(i)+i));
        }   
    
    
        //by while
        int i = -1;
        int j = src.length();
        while(++i<j){
            System.out.print(m1.get(""+src.charAt(i)+i));
        }
        [/code]
    

    只用Switch 做循环.真的不了解. 如果真能做出来估计也很难读懂.
    Only Switch. 呵呵.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?