代码编织梦想

public class Permutation {
public static void main(String[] args) {
char[] chs = {‘a’,‘b’,‘c’};
per(new char[3], chs, 3-1);
}
public static void per(char[] buf, char[] chs, int len){
if(len == -1){
for(int i=buf.length-1; i>=0; --i)
System.out.print(buf[i]);
System.out.println();
return;
}
for(int i=0; i<chs.length; i++){
buf[len] = chs[i];
per(buf, chs, len-1);
}
}
}

public class Arrange {
public static void main(String[] args) {
char[] chs = {‘a’,‘b’,‘c’};
arrange(chs, 0, chs.length);
}
public static void arrange(char[] chs, int start, int len){
if(start == len-1){
for(int i=0; i<chs.length; ++i)
System.out.print(chs[i]);
System.out.println();
return;
}
for(int i=start; i<len; i++){
char temp = chs[start];
chs[start] = chs[i];
chs[i] = temp;
arrange(chs, start+1, len);
temp = chs[start];
chs[start] = chs[i];
chs[i] = temp;
}
}
}

public class Comb {
public static void main(String[] args) {
char[] chs = {‘a’,‘b’,‘c’};
comb(chs);
}

public static void comb(char[] chs) {
	int len = chs.length;
	int nbits = 1 << len;
	for (int i = 0; i < nbits; ++i) {
		int t;
		for (int j = 0; j < len; j++) {
			t = 1 << j;
			if ((t & i) != 0) { // ??????1????1
				System.out.print(chs[j]);
			}
		}
		System.out.println();
	}
}

}

public class Permutation {
public static void main(String[] args) {
char[] chs = {‘a’,‘b’};
per(new char[2], chs, 2-1);
}
public static void per(char[] buf, char[] chs, int len){
if(len == -1){
for(int i=buf.length-1; i>=0; --i)
System.out.print(buf[i]);
System.out.println();
return;
}
for(int i=0; i<chs.length; i++){
buf[len] = chs[i];
per(buf, chs, len-1);
}
}
}

aa
ab
ba
bb

[Process completed - press Enter]

public class Permutation {
public static void main(String[] args) {
char[] chs = {’?’,’?’};
per(new char[2], chs, 2-1);
}
public static void per(char[] buf, char[] chs, int len){
if(len == -1){
for(int i=buf.length-1; i>=0; --i)
System.out.print(buf[i]);
System.out.println();
return;
}
for(int i=0; i<chs.length; i++){
buf[len] = chs[i];
per(buf, chs, len-1);
}
}
}

??
??
??
??

[Process completed - press Enter]

public class Permutation {
public static void main(String[] args) {
char[] chs = {’?’,’?’};
per(new char[2], chs, 2-1);
}
public static void per(char[] buf, char[] chs, int len){
if(len ==-1){
for(int i=buf.length-1; i>=0; --i)
System.out.print(buf[i]);
System.out.println();
return;
}
for(int i=0; i<chs.length; i++){
buf[len] = chs[i];
per(buf, chs,len-1);
}
}
}

??
??
??
??

[Process completed - press Enter]

import java.util.ArrayList;
import java.util.List;

public class CompoundString {

private static void generate(int n,List<String> results) {   
    if(n==1){
    	return;
    }
	List<String> resultsTemp_A = new ArrayList<String>();
	List<String> resultsTemp_B = new ArrayList<String>();
	for(String str : results){
    	String temp_A = str+"A";
    	resultsTemp_A.add(temp_A);
    	String temp_B = str+"B";
    	resultsTemp_B.add(temp_B);
    }
	//??results??????????????main????results???
	results.clear();
	results.addAll(resultsTemp_A);
	results.addAll(resultsTemp_B);
	generate(n-1, results);  // recursive
}  

public static void main(String[] args) {  
	List<String> results = new ArrayList<String>();
	results.add("A");
	results.add("B");
	generate(3, results);
	for(String str : results){
		System.out.println(str);
	}
}  

}

AAA
BAA
ABA
BBA
AAB
BAB
ABB
BBB

[Process completed - press Enter]

import java.util.ArrayList;
import java.util.List;

public class CompoundString {

private static void generate(int n,List<String> results) {   
    if(n==1){
    	return;
    }
	List<String> resultsTemp_A = new ArrayList<String>();
	List<String> resultsTemp_B = new ArrayList<String>();
	for(String str : results){
    	String temp_A = str+"A";
    	resultsTemp_A.add(temp_A);
    	String temp_B = str+"B";
    	resultsTemp_B.add(temp_B);
    }
	//??results??????????????main????results???
	results.clear();
	results.addAll(resultsTemp_A);
	results.addAll(resultsTemp_B);
	generate(n-1, results);  // recursive
}  

public static void main(String[] args) {  
	List<String> results = new ArrayList<String>();
	results.add("A");
	results.add("B");
	generate(2, results);
	for(String str : results){
		System.out.println(str);
	}
}  

}

AA
BA
AB
BB

[Process completed - press Enter]

import java.util.ArrayList;
import java.util.List;
/**

  • @author lyon_yao

*/
public class Test {
public static void main(String []a){
List list=new ArrayList();
String value=“0123456789abcdefghijklmnopqrstuvwmnxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”;
char[] chars=value.toCharArray();
for(char c:chars){
list.add(String.valueOf©);
}
System.out.println(list);
List result=new ArrayList();
for(char c:chars){
result.add(String.valueOf©);
}
new Test().run(list,1);
}
public void run(List last,int index){
int size = last.size();
for(int j=0;j<size-index;j++){
String temp="";
for(int i=0;i<index&&i+j<size;i++){
temp+=last.get(j+i);
}
System.out.println(temp);
}
if(index<size){
run(last,++index);
}
}
}

public class TestPL {
static String[] array = {“0”,“1”,“2”,“3”};

public static void main(String[] args) {
	for(int i=0;i<array.length;i++){
		sort("",i+1);
	}
}

public static void sort(String leftString, int leftLen){
	if(leftLen == 0){
		System.out.println(leftString);
		return;
	}
	for(int i=0;i<array.length;i++){
		if(leftString.indexOf(array[i]) != -1){
			continue;
		}else{
			sort(leftString+array[i],leftLen-1);
		}
	}
}

}

public class Permutation {
public static void main(String[] args) {
char[] chs = {‘a’,‘b’,‘c’};
per(new char[3], chs, chs.length-1);
}
public static void per(char[] buf, char[] chs, int len){
if(len == -1){
for(int i=buf.length-1; i>=0; --i)
System.out.print(buf[i]);
System.out.println();
return;
}
for(int i=0; i<chs.length; i++){
buf[len] = chs[i];
per(buf, chs, len-1);
}
}
}

public class Permutation {
public static void main(String[] args){
for(int i = 1;i <= 10;i++){
for (int j = 1;j<=i;j++){
System.out.print(i+""+j+"="+ij+"\t");
}
System.out.print("\n");
}
}
}

1=1
2
1=2 22=4
3
1=3 32=6 33=9
41=4 42=8 43=12 44=16
51=5 52=10 53=15 54=20 55=25
6
1=6 62=12 63=18 64=24 65=30 66=36
7
1=7 72=14 73=21 74=28 75=35 76=42 77=49
81=8 82=16 83=24 84=32 85=40 86=48 87=56 88=64
91=9 92=18 93=27 94=36 95=45 96=54 97=63 98=72 99=81
10
1=10 102=20 103=30 104=40 105=50 106=60 107=70 108=80 109=90 10*10=100

[Process completed - press Enter]

public class Permutation {
public static void main(String[] args){
for (int i = 1; i <= 9; i++){
for (int j = 1; j <= i; j++){
System.out.print(" " + i + “*” + j + “=” + (i * j)+"\t");
if(i == j)
System.out.print("\n");
}
}
}
}

11=1
2
1=2 22=4
3
1=3 32=6 33=9
41=4 42=8 43=12 44=16
51=5 52=10 53=15 54=20 55=25
6
1=6 62=12 63=18 64=24 65=30 66=36
7
1=7 72=14 73=21 74=28 75=35 76=42 77=49
81=8 82=16 83=24 84=32 85=40 86=48 87=56 88=64
91=9 92=18 93=27 94=36 95=45 96=54 97=63 98=72 9*9=81

[Process completed - press Enter]

至正确例题<2进制2位数秩序律法理式>
public class MultiplicationTable1{
public static void main(String[] args){
String[] a = {“0”,“1”};
for(int i = 0;i < 2;i++)
for(int j = 0;j < 2;j++)
System.out.print( a[i]+a[j]+"\n");
}
}

至正确例题<2进制2位数秩序律法理式>
public class MultiplicationTable1{
public static void main(String[] args){
String[] a = {“0”,“1”};
for(int i = 0;i < 2;i++){
for (int j = 0;j<2;j++){
System.out.print( a[i]+a[j]+"\n" );
}
}
}
}

至正确例题<2进制2位数秩序律法理式>
public class MultiplicationTable1{
public static void main(String[] args){
String[] a = {“0”,“1”};
for(int i = 0;i < 2;i++){
for (int j = 0;j<2;j++){
System.out.print(a[i]+a[j]+"\n");
}
}
}
}

String[] arr = {“a”,“b”};
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}

String[] bArray = {“a”,“b”,“c”, “d”, “e”};

for(int i=0;i<sums.length;i++){
System.out.println(sums[i]);
}

正确例题
public class MultiplicationTable1{
public static void main(String[] args){
String[] arr = {“a”,“b”};
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
}

正确例题
public class MultiplicationTable1{
public static void main(String[] args){
String [] names ={“James”, “Larry”, “Tom”, “Lacy”};
for( String name : names ) {
System.out.print( name );
System.out.print(",");
}
}
}

正确例题
public class MultiplicationTable1{
public static void main(String[] args){
String [] as ={“0”, “1”};
for( String a : as ) {
System.out.print( a );
System.out.print("");
}
}
}

正确例题
public class MultiplicationTable1{
public static void main(String[] args){
String [] s ={“0”, “1”};
for(int a = 0;a < 2;a++){
System.out.print( s[a] );
System.out.print("");
}
}
}

正确例题
public class MultiplicationTable1{
public static void main(String[] args){
String [] as ={“0”, “1”};
for( String a : as ) {
System.out.print( a );
}
}
}

正确例题
public class MultiplicationTable1{
public static void main(String[] args){
String [] a ={“0”, “1”};
for(int i = 0;i < 2;i++)
System.out.print( a[i] );
}
}

正确例题
public class MultiplicationTable1{
public static void main(String[] args){
String [] as ={“a”, “b”, “c”, “d”};
for( String a : as ) {
System.out.print( a );
System.out.print("");
}
}
}

正确例题
public class Permutation {
public static void main(String[] args){
String arr[] = new String[]{“a”,“b”,“c”};
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
}

至正确例题<2进制2位数秩序律法理式>
public class MultiplicationTable1{
public static void main(String[] args){
String[] a = {“a”,“b”};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
System.out.println(a[i]+a[j]);
}
}

aa
ab
ba
bb

[Process completed - press Enter]

至正确例题<2进制2位数秩序律法理式>
public class Permutation {
public static void main(String[] args){
String a [] = {“负”,“正”};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
System.out.println(a[i]+a[j]);
}
}

负负
负正
正负
正正

[Process completed - press Enter]

秩序代码正确版<2进制2位数秩序律法理式>
public class Test {
public static void main(String args[]){
String a [] ={“红”,“绿”};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
System.out.print(a[i]+a[j]+"\n");
System.out.print("");
}
}

秩序代码正确版<2进制2位数秩序律法理式>
public class Permutation {
public static void main(String[] args){
String a [] = {“0”,“1”};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
System.out.println(a[i]+a[j]);
}
}

至正确例题<2进制3位数秩序律法理式>
public class Permutation {
public static void main(String[] args){
String a [] = {“0”,“1”};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
System.out.println(a[i]+a[j]+a[k]);
}
}

000
001
010
011
100
101
110
111

[Process completed - press Enter]

至正确例题<3进制3位数秩序律法理式>
public class Permutation {
public static void main(String[] args){
String[] a = {“0”,“1”,“2”};
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
System.out.println(a[i]+a[j]+a[k]);
}
}

000
001
002
010
011
012
020
021
022
100
101
102
110
111
112
120
121
122
200
201
202
210
211
212
220
221
222

[Process completed - press Enter]

正确例题
public class Permutation {
public static void main(String[] args){
String[] a = {“a”,“b”,“c”,“d”,“e”,“f”,“g”,“h”,“i”,“j”,“k”,“l”,“m”,“n”,“o”,“p”,“q”,“r”,“s”,“t”,“u”,“v”,“w”,“x”,“y”,“z”,“A”,“B”,“C”,“D”,“E”,“F”,“G”,“H”,“I”,“J”,“K”,“L”,“M”,“N”,“O”,“P”,“Q”,“R”,“S”,“T”,“U”,“V”,“W”,“X”,“Y”,“Z”,“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,"[","]","^","_","`",":",";","<","=",">","","?","","@","{","|","}","~","!","","$","%","&","’","(",")","*","+",",","-",".","/"};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
if(i!=j&&j!=i)
System.out.println(a[i]+a[j]);
}
}

ab
ba

[Process completed - press Enter]

正确例题
public class Permutation {
public static void main(String[] args){
String[] a = {“a”,“b”,“c”,“d”,“e”,“f”,“g”,“h”,“i”,“j”,“k”,“l”,“m”,“n”,“o”,“p”,“q”,“r”,“s”,“t”,“u”,“v”,“w”,“x”,“y”,“z”,“A”,“B”,“C”,“D”,“E”,“F”,“G”,“H”,“I”,“J”,“K”,“L”,“M”,“N”,“O”,“P”,“Q”,“R”,“S”,“T”,“U”,“V”,“W”,“X”,“Y”,“Z”,“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,"[","]","^","_","`",":",";","<","=",">","","?","","@","{","|","}","~","!","","$","%","&","’","(",")","*","+",",","-",".","/"};
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
if(i!=j&&i!=k&&j!=i&&j!=k&&k!=i&&k!=j)
System.out.println(a[i]+a[j]+a[k]);
}
}

abc
acb
bac
bca
cab
cba

[Process completed - press Enter]

正确例题
public class Permutation {
public static void main(String[] args){
String[] a = {“a”,“b”,“c”,“d”,“e”,“f”,“g”,“h”,“i”,“j”,“k”,“l”,“m”,“n”,“o”,“p”,“q”,“r”,“s”,“t”,“u”,“v”,“w”,“x”,“y”,“z”,“A”,“B”,“C”,“D”,“E”,“F”,“G”,“H”,“I”,“J”,“K”,“L”,“M”,“N”,“O”,“P”,“Q”,“R”,“S”,“T”,“U”,“V”,“W”,“X”,“Y”,“Z”,“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,"[","]","^","_","`",":",";","<","=",">","","?","","@","{","|","}","~","!","","$","%","&","’","(",")","*","+",",","-",".","/"};
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
for(int l=0;l<4;l++)
if(i!=j&&i!=k&&i!=l&&j!=i&&j!=k&&j!=l&&k!=i&&k!=j&&k!=l&&l!=i&&l!=j&&l!=k)
System.out.println(a[i]+a[j]+a[k]+a[l]);
}
}

abcd
abdc
acbd
acdb
adbc
adcb
bacd
badc
bcad
bcda
bdac
bdca
cabd
cadb
cbad
cbda
cdab
cdba
dabc
dacb
dbac
dbca
dcab
dcba

[Process completed - press Enter]

java输出加法表
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner input =new Scanner (System.in);
System.out.println(“输入一个数”);
int i =input.nextInt();
int x=0;
int y=i;
System.out.println(“根据这个值可以输出如下加法表”);
for(x=0,y=i;x<=i&&y>=0;x++,y–){
System.out.println(x+"+"+y+"="+i);
}
}
}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/qq_32257509/article/details/111061061