J
johnnyringo888
I have to create a diamond shape for my java class.
*
***
*****
*******
*********
*******
*****
***
*
Here is the code I have written so far. Can any provide assistance?
public class Diamond
{
public static void main (String[] args)
{
for ( int i = 1; i <= 10; i++ )
{
for ( int j = 0; j < i; j++ )
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
for ( int i = 10; i > 0; i-- )
{
for ( int j = 0; j < i; j++ )
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
for ( int i = 10; i > 0; i-- )
{
for ( int j = 0; j < (10 - i); j++ )
{
System.out.print (" ");
} }
for ( int j = 0; j < i; j++ )
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
for ( int i = 1; i <= 10; i++ )
{
for ( int j = 0; j < (10 - i); j++ );
{
System.out.print (" ");
}
for ( int j = 0; j < i; j++ );
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
}
}
When I compile this is what I get:
*
**
***
****
*****
******
*******
********
*********
**********
**********
*********
********
*******
******
*****
****
***
**
*
**********
*********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
******
*******
********
*********
**********
*
***
*****
*******
*********
*******
*****
***
*
Here is the code I have written so far. Can any provide assistance?
public class Diamond
{
public static void main (String[] args)
{
for ( int i = 1; i <= 10; i++ )
{
for ( int j = 0; j < i; j++ )
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
for ( int i = 10; i > 0; i-- )
{
for ( int j = 0; j < i; j++ )
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
for ( int i = 10; i > 0; i-- )
{
for ( int j = 0; j < (10 - i); j++ )
{
System.out.print (" ");
} }
for ( int j = 0; j < i; j++ )
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
for ( int i = 1; i <= 10; i++ )
{
for ( int j = 0; j < (10 - i); j++ );
{
System.out.print (" ");
}
for ( int j = 0; j < i; j++ );
{
System.out.print ("*");
}
{
System.out.println ("\n");
}
}
}
}
When I compile this is what I get:
*
**
***
****
*****
******
*******
********
*********
**********
**********
*********
********
*******
******
*****
****
***
**
*
**********
*********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
******
*******
********
*********
**********