A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 黑马嗨嗨嗨 高级黑马   /  2016-11-15 15:01  /  1496 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

最近看到for循环语句,用for循环语句显示一个金字塔时,就有一个想法,能不能用for语句显示一个爱心,感觉这可以成为程序员表白专用啊!有大神知道吗?

来自宇宙超级黑马专属苹果客户端来自宇宙超级黑马专属苹果客户端

4 个回复

倒序浏览
想法完美
回复 使用道具 举报
回复 使用道具 举报 1 0
哈哈 百度下 没准能找到
回复 使用道具 举报

[AppleScript] 纯文本查看 复制代码
public static void main(String[] args) {
		System.out.println(callBack("*"));
		System.out.println(callBack("0"));
	}
	public static String callBack(String input) {
		int[] array = { 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 4, 5, 2, 3, 4, 1, 0, 1,
				0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < array.length; i++) {
			if (i % 7 == 0)
				sb.append("  \n");
			if (array[i] == 0) 
				sb.append("   ");
			 else if (array[i] == 4) 
				sb.append("  ");
			 else if (array[i] == 5) 
				sb.append(" I ");
			 else if (array[i] == 2) 
				sb.append("Lvoe ");
			 else if (array[i] == 3) 
				sb.append("You");
			 else {
				sb.append("  " + input);
			}
		}
		return sb.toString();
	}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马