프로 그래 밍 사상의 길(1)-자바 99 곱셈 표 인쇄 16 가지 실현 방식

package com.hua.algorithm;

public class Demo01 {

	public static void main(String[] args) {
		// method1();           //   for      99    
		// method2();		//   for      99    
		// method3(1);		//       99    
		// method4(9);		//         99    
		// method5();		//   while    99   
		// method6();		//   while        99   
		// method7();		//    for      99   
		// method8();		//    for      99   
		// method9();		//   do..while      99   
		// method10();		//   do...while      99   
		// method11();		//     while      99   
		// method12();		//     while      99   
		// method13();		//     do...while    99   
		// method14();		//     do...while      99   
		// method15(1,1);	//         99   
		method16(1,9);		//         99   
	}

	/**
	 *         99   
	 */
	private static void method16(int i, int row) {
		System.out.print(i + "*" + row + "=" + i*row + "\t");
		if (i== row && row > 1) {
			System.out.println();
			row--;
			i = 0;
		}else if (i== row && row == 1) {
			return;
		}
		
		i++;
		method16(i, row);
	}

	/**
	 *         99   
	 */
	private static void method15(int i,int row) {
		System.out.print(i + "*" + row + "=" + i*row + "\t");
		if (i == row && row < 9) {
			System.out.println();
			row++;
			i = 0;
		}else if(i == row && row == 9){
			return;
		}
		i++;
		method15(i, row);
	}

	/**
	 *     do...while      99   
	 */
	private static void method14() {
		int row = 9;
		int i = 1;
		do {
			System.out.print(i + "*" + row + "=" + i*row + "\t");
			if (i == row) {
				System.out.println();
				row--;
				i = 0;
			}
			i++;
		} while (row >= 1);
	}

	/**
	 *     do...while    99   
	 */
	private static void method13() {
		int row = 1;
		int i = 1;
		do {
			System.out.print(i + "*" + row + "=" + i*row + "\t");
			if (i==row) {
				System.out.println();
				row++;
				i = 0;
			}
			i++;
		} while (row <= 9);
	}

	/**
	 *     while      99   
	 */
	private static void method12() {
		int row = 9;
		int i = 1;
		while (row >= 1) {
			System.out.print(i + "*" + row + "=" + i*row + "\t");
			if (i == row) {
				System.out.println();
				row--;
				i = 0;
			}
			i++;
		}
	}

	/**
	 *     while      99   
	 */
	private static void method11() {
		int row = 1;
		int i = 1;
		while (row <= 9) {
			System.out.print(i + "*" + row + "=" + i*row + "\t");
			if(i == row){
				System.out.println();
				i = 0;
				row++;
			}
			i++;
		}
		
	}

	/**
	 *   do...while      99   
	 */
	private static void method10() {
		int row = 9;
		do {
			int i = 1;
			do {
				System.out.print(i + "*" + row + "=" + i*row + "\t");
				i++;
			} while (i <= row);
			System.out.println();
			row--;
		} while (row >= 1);
	}

	/**
	 *   do..while      99   
	 */
	private static void method9() {

		int row = 1;
		do {
			int i = 1;
			do {
				System.out.print(i + "*" + row + "=" + i*row + "\t");
				i++;
			} while (i <= row);
			System.out.println();
			row++;
		} while (row <= 9);
	}

	/**
	 *    for      99   
	 */
	private static void method8() {
		for (int row = 9,j = 1; row >= 1; j++) {
			System.out.print(j + "*" + row + "=" + j*row + "\t");
			if (j == row) {
				System.out.println();
				row--;
				j = 0;
			}
		}
	}

	/**
	 *    for      99   
	 * 	    
	 * 		1.  for      9 
	 * 		2.             ,         
	 */
	private static void method7() {
		for (int row = 1,j = 1; row <= 9; j++) {
			System.out.print(j + "*" + row + "=" + j*row + "\t");
			if (j == row) {
				System.out.println();
				row++;
				j = 0;
			}
		}
	}


	/**
	 *   while        99   
	 * 
	 */
	private static void method6() {
		int row = 9;
		while (row >= 1) {
			int i = 1;
			while (i <= row) {
				System.out.print(i + "*" + row + "=" + i*row + "\t");
				i++;
			}
			System.out.println();
			row--;
		}
	}

	/**
	 *   while    99   
	 */
	private static void method5() {
		int row = 1;
		while (row <= 9) {
			int j = 0;
			while(j++ <= row){
				System.out.print(j + "*" + row + "=" +j*row + "\t");
			}
			System.out.println();
			row++;
		}
	}

	/**
	 *         99    
	 * 	     
	 * 		1.     9  
	 * 		2.     9 ,     8            
	 */
	private static void method4(int number) {
		for (int i = 1; i <= number; i++) {
			System.out.print(i + "*" + number + "=" + i * number + "\t");
		}
		number--;
		if (number >= 1) {
			System.out.println();
			method4(number);
		}

	}

	/**
	 *       99    
	 *     : 
	 * 	1.     9  
	 * 	2.          
	 * 	3. 9   9            
	 */
	private static void method3(int number) {
		for (int i = 1; i <= number; i++) {
			System.out.print(i + "*" + number + "=" + i * number + "\t");
		}
		number++;
		if (number <= 9) {
			System.out.println();
			method3(number);
		}
	}

	/**
	 *   for      99    
	 * 	     
	 * 		1.   9  
	 * 		2.     9 ,     8             
	 * 		3.            
	 */
	private static void method2() {
		for (int i = 9; i >= 1; i--) {
			for (int j = 1; j <= i; j++) {
				System.out.print(j + "*" + i + "=" + i * j + "\t");
			}
			System.out.println();
		}
	}

	/**
	 *   for      99    
	 * 	     
	 * 		1.   9  
	 * 		2.       ,     2 ,         9  
	 * 		3.     ,    
	 */
	private static void method1() {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(j + "*" + i + "=" + i * j + "\t");
			}
			System.out.println();
		}
	}

}


좋은 웹페이지 즐겨찾기