打印出字母K和空心正方形

来源:互联网 发布:apus 浏览器 知乎 编辑:程序博客网 时间:2024/04/28 13:37

正方形


public class shape {



/**
* @param args
*/
public static void main(String[] args) {
int n=5;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==0||j==0||i==n-1||j==n-1)
System.out.print("* ");
else
System.out.print("  ");
}
System.out.println();
}
}

}


字母K 


public class shapek {
public static void main(String[] args) {
int n = 5;
for(int i=1;i<n*2;i++){
for(int j=0;j<=Math.abs(n-i);j++){
if(j==0||j==Math.abs(n-i))
{
System.out.print("* ");
}
else
System.out.print("  ");
}
System.out.println();
}
}
}


0 0
原创粉丝点击