用java的for循环输出空心菱形
展开全部
import java.util.Scanner;
public class LingXKX
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入菱形变长:");
int num =sc.nextInt();
for (int i=1;i<=num;i++)
{
for(int j=1;j<num-i+1;j++)
{
System.out.print(" ");
}
int count =2*i-1;
for(int k=0;k<count;k++)
{
if(0==k||count-1==k)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println("");
}
for(int i=1;i<num;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(" ");
}
int count = 2*(num-i)-1;
for(int k=0;k<count;k++)
{
if(k==0||k==count-1)
System.out.print("*");
else
System.out.print(" ");
}System.out.println("");
}
}
}
public class LingXKX
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入菱形变长:");
int num =sc.nextInt();
for (int i=1;i<=num;i++)
{
for(int j=1;j<num-i+1;j++)
{
System.out.print(" ");
}
int count =2*i-1;
for(int k=0;k<count;k++)
{
if(0==k||count-1==k)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println("");
}
for(int i=1;i<num;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(" ");
}
int count = 2*(num-i)-1;
for(int k=0;k<count;k++)
{
if(k==0||k==count-1)
System.out.print("*");
else
System.out.print(" ");
}System.out.println("");
}
}
}
展开全部
public class Kong{
public static void main(String []args){
int hangshu = 11;
int yiban = hangshu / 2 + 1;
int yibanduo = hangshu / 2;
for(int k = 1;k <= yiban;k++){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
for(int k = yibanduo;k >=1;k--){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
}
}
public static void main(String []args){
int hangshu = 11;
int yiban = hangshu / 2 + 1;
int yibanduo = hangshu / 2;
for(int k = 1;k <= yiban;k++){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
for(int k = yibanduo;k >=1;k--){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询