• 使用for循环打印爱心


     代码如下

    public class Heart {
    public static void main(String[] args) {
    // 分三个大部分 上中下
    for (int i = 0, k = 0; i < 14; i++) {// 打印行
    // 上部分 上分为 四个部分
    if (i < 3) {
    for (int j = 0; j < 5 - 2 * i; j++) {// 1、空心
    System.out.print(" ");
    }
    if (i == 2) {// 2、*
    for (int j = 0; j < 6 + 4 * i - 1; j++) {
    System.out.print("*");
    }
    for (int j = 0; j < 7 - 4 * i + 2; j++) {// 3、空心
    System.out.print(" ");
    }
    for (int j = 0; j < 6 + 4 * i - 1; j++) {// 4、*
    System.out.print("*");
    }
    } else {
    for (int j = 0; j < 6 + 4 * i; j++) {// 2、*
    System.out.print("*");
    }
    for (int j = 0; j < 7 - 4 * i; j++) {// 3、空心
    System.out.print(" ");
    }
    for (int j = 0; j < 6 + 4 * i; j++) {// 4、*
    System.out.print("*");
    }
    }
    } else if (i < 6) {// 中间
    for (int j = 0; j < 29; j++) {
    System.out.print("*");
    }
    } else {// 下部分 6
    if (i == 13) {
    for (int j = 0; j < 2 * (i - 6); j++) {// 打印空格
    System.out.print(" ");
    }
    System.out.print("*");
    } else {
    for (int j = 0; j < 2 * (i - 6) + 1; j++) {// 打印空格
    System.out.print(" ");
    }
    for (int j = 1; j < 28 - 4 * k; j++) {
    System.out.print("*");
    }
    k++;
    }
    }
    System.out.println();
    }

    }

    }

    相信自己,坚信自己的目标,去承受常人承受不了的磨难与挫折,不断的努力去奋斗,最终的成功就会是你
  • 相关阅读:
    java1.5新特性
    [转载]传智播客_SQL入门
    集合类的应用
    多线程的应用
    包的使用
    异常的应用finally与总结
    自定义异常以及runtime类
    异常的处理
    SpringMVC_05 利用spring框架来处理异常
    SpringMVC_04 拦截器 【拦截器的编程步骤】【session复习?】
  • 原文地址:https://www.cnblogs.com/Valuez/p/13418618.html
Copyright © 2020-2023  润新知