How to make a diamond using Nested For Loops

后端 未结 15 1350
终归单人心
终归单人心 2021-01-01 07:09

So I was assigned to make a diamond with asterisks in Java and I\'m really stumped. Here\'s what I\'ve come up with so far:

public class Lab1 
{
   public s         


        
15条回答
  •  佛祖请我去吃肉
    2021-01-01 07:57

        for (int i = 0; i < 5; i++) 
              System.out.println("    *********".substring(i, 5 + 2*i));
    
        for (int i =5; i>0;i--)
            System.out.println("     **********".substring(i-1,5+(2*i)-3));
    

提交回复
热议问题