java中的形状(心形)。不是本人写的,只为娱乐
程序员文章站
2022-03-20 10:14:56
...
package am;
public class Demo03 {
public static void main(String[] args) {
System.out.println(printHeart("*"));
}
private static String printHeart(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();
}
}
上一篇: Python绘制心形图案
下一篇: 贝塞尔曲线的艺术---弹性效果实现