Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:如何生成x位A-Z的字串呢? [Re:binge]
chance2000





发贴: 5
积分: 0
于 2006-05-24 18:16 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
//替换字符串中的index位为newChar
public static String replaceIndex(String oldStr, int index, char newChar) {
return oldStr.substring(0, index) +
newChar + oldStr.substring(index + 1, oldStr.length());
}
//生成x位的A-Z的字串
public static void doIt(int n) {
int idx = 0;
String start = "";
String[] arr = new String[26];
StringBuffer sb = new StringBuffer(2048);

for (int i = 0; i < n; i++) {
start = start + "A";
}

for (char c = 'A'; c <= 'Z'; c++) {
arr[idx] = replaceIndex(start, n - 1, c);
sb.append(arr[idx]);
sb.append(" ");
idx++;
}
sb.append("\n");
idx = 0;
n--;
while ( (--n) >= 0) {
for (char c = 'B'; c <= 'Z'; c++) {
for (int i = 0; i < 26; i++) {
String tmp = replaceIndex(arr[i], n, c);
sb.append(tmp);
sb.append(" ");
if (c == 'Z') {
arr[i] = tmp;
}
idx++;
}
sb.append("\n");
}
}
System.out.println(sb.toString());
}

public static void main(String args[]) {
doIt(4);
}

这个不知道是不是你要的结果?这个效率应该还算可以。




话题树型展开
人气 标题 作者 字数 发贴时间
7147 如何生成x位A-Z的字串呢? binge 379 2006-05-17 12:29
5747 Re:如何生成x位A-Z的字串呢? why 132 2006-05-18 18:15
5740 Re:如何生成x位A-Z的字串呢? xicheng1 23 2006-05-19 17:12
5933 Re:如何生成x位A-Z的字串呢? Jcat 902 2006-05-21 00:11
6001 Re:如何生成x位A-Z的字串呢? Jcat 1584 2006-05-21 00:26
5750 Re:如何生成x位A-Z的字串呢? oujianqiang 643 2006-05-22 17:53
5759 Re:如何生成x位A-Z的字串呢? binge 116 2006-05-23 19:31
6029 Re:如何生成x位A-Z的字串呢? chance2000 1168 2006-05-24 18:16

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923