java - Print a pattern like AAA to ZZZ starts like AAA AAB AAC.... AAZ ABA ABB ... ZZZ? -
i have tried below code shows error..
string str="aaa"; char[] ch=str.tochararray(); int length=str.length(); for(int i=length-1;i>=0;i--) { for(int j=65;j<=90;j++) { system.out.println(str.replace(ch[i] ,(char)j)); } }
all need 3 loops (one each character place):
for(char c1 = 'a'; c1 <= 'z'; c1++){ for(char c2 = 'a'; c2 <= 'z'; c2++){ for(char c3 = 'a'; c3 <= 'z'; c3++){ system.out.println("" + c1 + c2 + c3); } } }
at end adding string, or else numerical value, instead of string expecting:
system.out.println('a' + 'b' + 'c'); // output: 198 system.out.println("" + 'a' + 'b' + 'c'); // output: abc
Comments
Post a Comment