Thursday 20 July 2017

java program for print stars in X shape

public class Cross {
public static void main(String[] args) {

int n=9;
for(int i=1;i<=n;i++){

for(int j=1;j<=n;j++)
{
if(i==j||i+j==n+1)
System.out.print("*");
else
System.out.print("     ");
}
System.out.println();
}
}
}





OUTPUT:


*                                        *
     *                              *  
          *                     *        
               *            *            
                    *   *
                      *
                   *    *                  
              *            *            
         *                    *        
    *                             *  

*                                        *

No comments:

Post a Comment