String str=”WeeciolGmmcc”
分别用for,while,switch3种循环写出程序,使程序能打印出WelcomeGmcic,
一个打印语句只能打印出一个字符
大家帮忙看看这到面试题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
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. 呵呵.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报