一个编程问题,我甚至不知道他属于什么类型 题目:有一个String类型的变量 str="login",要求输出他的所有可能的任意大小写组合的结果,如:“Login,LOgin,LoGiN......”请回复整个程序代码,用System.out.print语句打印结果有不明白的地方,可以跟帖追问,:) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是个二进制。0代表小写,1代表大写login供5个字母,你就从 00000 遍历到 11111 ,完成任务。总计 0 ~ 31 供32种组合。 for examplepublic class Test { public static void main(String[] args) throws Throwable { String s = "login".toLowerCase(); char[] c = s.toCharArray(); int[] idx = new int[c.length]; StringBuilder buf = new StringBuilder(); while (idx[0] < 2) { buf.delete(0, buf.length()); for (int i=0; i<idx.length; i++) { if (idx[i] == 1) { buf.append(Character.toUpperCase(c[i])); } else { buf.append(c[i]); } } System.out.println(buf); idx[idx.length-1]++; for (int i=idx.length-1; i>0; i--) { if (idx[i] == 2) { idx[i] = 0; idx[i-1]++; } else { break; } } } }} 4楼的好像没考虑Olgin,Golin这样组合的问题吧 public class Test26 { public static void main(String[] args) { String str = "lOgiN"; String lowStr = str.toLowerCase(); int length = lowStr.length(); for(int i=0; i<(int)Math.pow(2, lowStr.length());i++){ char[] ch = lowStr.toCharArray(); String s = Integer.toBinaryString(i); for(int j=0; j<s.length(); j++){ if('1' == s.charAt(s.length() -j -1)) { ch[length - j -1] = (char)(ch[length - j -1] - 32); } } System.out.println(new String(ch)); } }} JNative指针释放问题 关于数据库连接是否要单利的问题? Struts1 redirect的问题 j2EE开发项目实例 使用Struts2.1.6后无法显示WebRoot根目录的文件 java中prepareStatement问题 java 菜鸟求助 用struts实现数组的读取和修改,实在调不出来了。 初学Struts,一个问题,谢谢 我用JDOM来读XML文件,为什么在TOMCAT4。0下就好好的一到TOMCAT4。1就出错?谁遇见过? 用ssh做一个向数据库中存储前台数据时出现了以下异常,哪位大神帮忙解答以下 如何将字串符转换为JSON格式
public static void main(String[] args) throws Throwable {
String s = "login".toLowerCase();
char[] c = s.toCharArray();
int[] idx = new int[c.length];
StringBuilder buf = new StringBuilder();
while (idx[0] < 2) {
buf.delete(0, buf.length());
for (int i=0; i<idx.length; i++) {
if (idx[i] == 1) {
buf.append(Character.toUpperCase(c[i]));
} else {
buf.append(c[i]);
}
}
System.out.println(buf); idx[idx.length-1]++;
for (int i=idx.length-1; i>0; i--) {
if (idx[i] == 2) {
idx[i] = 0;
idx[i-1]++;
} else {
break;
}
}
}
}
}
public class Test26 { public static void main(String[] args) {
String str = "lOgiN";
String lowStr = str.toLowerCase();
int length = lowStr.length();
for(int i=0; i<(int)Math.pow(2, lowStr.length());i++){
char[] ch = lowStr.toCharArray();
String s = Integer.toBinaryString(i);
for(int j=0; j<s.length(); j++){
if('1' == s.charAt(s.length() -j -1))
{
ch[length - j -1] = (char)(ch[length - j -1] - 32);
}
}
System.out.println(new String(ch));
}
}
}