本帖最后由 施大勇 于 2013-9-28 15:29 编辑
- package lesson4;
- /*
- 通过嵌FOR循环实现几种复杂不同图案的打印
- */
- public class Tuxing {
- /**
- * 打印图形
- */
- public static void main(String[] args) {
- printTuxing1();
- System.out.println("------------------------------------");
- printTuxing2();
- System.out.println("------------------------------------");
- printTuxing3();
- System.out.println("------------------------------------");
- printTuxing3_1();
- System.out.println("------------------------------------");
- printTuxing4();
- }
- private static void printTuxing1() {
- for (int i = 0; i < 5; i++) {
- for (int k = 0; k < i; k++) {
- System.out.print(" ");
- }
- for (int j = 0; j < 10; j++) {
- System.out.print("*");
- }
- System.out.println();
-
- }
-
- }
-
- private static void printTuxing2() {
- for (int i = 0; i < 5; i++) {
- for (int k = i; k < 5; k++) {
- System.out.print(" ");
- }
- for (int j = 0; j < 10; j++) {
- System.out.print("*");
- }
- System.out.println();
-
- }
-
- }
-
- private static void printTuxing3() {
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < i+1; j++) {
- System.out.print("*");
- }
- System.out.println();
-
- }
- for (int x = 0; x < 4; x++) {
- for (int y = x; y < 4; y++) {
- System.out.print("*");
- }
- System.out.println();
- }
-
- }
-
- private static void printTuxing3_1() {
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < i+1 && i<6; j++) {
- System.out.print("*");
- }
- for (int j =i ; j < 10 && i>=6; j++) {
- System.out.print("*");
- }
- System.out.println();
-
- }
- }
-
- private static void printTuxing4() {
- for (int i = 0; i < 3; i++) {
- for (int j = i; j < 2; j++) {
- System.out.print(" ");
- }
- for (int j = 0; j < i+1 && i<3; j++) {
- System.out.print("*");
- }
- System.out.println();
- }
-
- }
- }
复制代码 |