How can I optimize this code to have fewer loops and return values for unit testing? public class Diamond {public void DiamondShape(int num) {   for(int ucount=num;ucount>0;ucount--) {//Loop to print blank space    for(int count_sp=1;count_sp<ucount;count_sp++)        System.out.printf( );//Loop to print *    for(int count_ast=num;count_ast>=ucount;count_ast--)        System.out.printf(* );    System.out.println();   }//Loop for lower half  for(int lcount=1;lcount<num;lcount++) {    //Loop to print blank space    for(int count_sp=0;count_sp<lcount;count_sp++)            System.out.printf( );    //Loop to print *        for(int count_ast=num-1;count_ast>=lcount;count_ast--)            System.out.printf(* );    System.out.println();    }  } }Output when num = 3:   *  * * * * *  * *   *This is how the output should be. num indicates the star in center line.
Printing a diamond-shaped figure
java;unit testing;formatting;junit