输入1234 5678 90ab cdef 输出12348bfedc9567a0

	/**
	 * (转载)
	 * @author blog4Leon
	 * 
	 * 输入 
	 * 1234
	 * 5678 
	 * 90ab 
	 * cdef 
	 * 输出 
	 * 12348bfedc9567a0
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		char[][] chars = {
				{ '1', '2', '3', '4' }, 
				{ '5', '6', '7', '8' },
				{ '9', '0', 'a', 'b' },
				{ 'c', 'd', 'e', 'f' } };

		int columnNum = chars[0].length;
		int rowNum = chars.length;

		printCharArray(rowNum, columnNum, chars);
	}

	private static void printCharArray(int rowNum, int columnNum, char[][] chars) {

		// 输出数组第一行
		for (int i = 0; i < columnNum; i++) {
			System.out.print(chars[0][i]);
		}

		// 对未遍历的子数组做一次行列交换
		if (rowNum > 0 && columnNum > 0) {
			int newRowNum = columnNum;
			int newColumnNum = rowNum - 1;
			char[][] newChars = new char[newRowNum][newColumnNum];
			for (int i = 0; i < newRowNum; i++) {
				for (int j = 0; j < newColumnNum; j++) {
					newChars[i][j] = chars[j + 1][newRowNum - i - 1];
				}
			}

			// 递归
			printCharArray(newRowNum, newColumnNum, newChars);
		}
	}

你可能感兴趣的:(C++,c,C#,F#,J#)