JAVA笔试题

由于朋友去面试遇到“JAVA 输出左右上下对称的图形” 这道题,特记下以便自己遇到时也能做!哈哈!

public class PrintSymmetrical {
	
	public static void main(String[] args) {
		
		for (int i = 0; i <= 3; i++) {
			for (int j = 0; j <= 2 - i; j++) {
				System.out.print(" ");
			}
			for (int k = 0; k <= 2 * i; k++) {
				System.out.print("*");
			}
			System.out.println("");
		}
		
		for (int i = 0; i <= 2; i++) {
			for (int j = 0; j <= i; j++) {
				System.out.print(" ");
			}
			for (int k = 0; k <= 4 - 2*i; k++) {
				System.out.print("*");
			}
			System.out.println("");
		}
		
		System.out.println("+++++++++++++这是分割线+++++++++++++");
		
		int count = 1; 
		
		for (int i = 0; i <= 3; i++) {
			for (int j = 0; j <= 2 - i; j++) {
				System.out.print(" ");
			}
			for (int k = 0; k <= 2 * i; k++) {
				System.out.print(count++);
			}
			count = 1;
			System.out.println("");
		}
		
		
		for (int i = 0; i <= 2; i++) {
			for (int j = 0; j <= i; j++) {
				System.out.print(" ");
			}
			for (int k = 0; k <= 4 - 2*i; k++) {
				System.out.print(count++);
			}
			count = 1;
			System.out.println("");
		}
		
	}

}


输出如下:
   *
  ***
*****
*******
*****
  ***
   *
+++++++++++++这是分割线+++++++++++++
   1
  123
12345
1234567
12345
  123
   1


你可能感兴趣的:(java,面试,J#)