栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java打印心形

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java打印心形

(实际操作比较鸡肋)

class Exer1{
	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();// 换行
		}
	}
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/716673.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号