import java.io.*; // package for Java input/ output classes public class TestDiamond //The main method. The driver for testing the Test Diamond class{ public static void main(String[] args)throws IOException // takes an input of a number and a character and outputs a diamond using the input { int number; // stores the number String character; // stores the character BufferedReader inData; //Input stream for strings inData = new BufferedReader(new InputStreamReader(System.in)); //Declares and creates an instance of buffered reader System.out.println("Please enter a Number: "); // Displays a message for the reader, asking to insert a number number = Integer.parseInt(inData.readLine()); // reads in the number inputed System.out.println("Please enter a character: "); // Displays a message for th reader asking to insert a character character = inData.readLine(); // reads in the character inputed for(int i=0;i<number;i=i+2)// a count control loop statement that declares the variable i, sets it to 0, //adds 2 to i, and if i is less than the number inputed the loop exeuctes { for(int x=0;x<number;x++) // a count controlled loop statement that declares the variable x, and sets it to 0 // increments x by 1 and compares x as less than the number inputed { int start =(number-i)/2; // declares a variable start and sets it to equal to number -i divided by 2 int end = start+i; // declares a variable end and sets it to start + i if(x<start || x>end) // a event control loop which has the conditions of x is less than start or x is greater than end { System.out.print (" "); // if the if statement returns true it prints a blank, which is what this statement does. } else // if the If statement isn't true this loop executes { System.out.print (character); // prints the character inputed earlier } } System.out.println (""); // prints a new line, which is blank } for(int i=number-1;i>=-1;i=i-2)// a count control loop statement that declares the variable i, sets it to equal the number minus 1, //minus 2 to i, and if i is less than negative one the loop exeuctes { for(int x=number-1;x>=-1;x--)// a count controlled loop statement that declares the variable x, and sets it to equal the number // decrements x by 1 and compares x as greater than or equal to minus one { int start = ((number-i)/2);// declares a variable start and sets it to equal to number -i divided by 2 int end = start+i; // declares a variable end and sets it to start + i if(x<=start || x>=end) // a event control loop which has the conditions of x is less than or equal to //start or x is greater than or equal to end { System.out.print (" "); // if the if statement returns true it prints a blank, which is what this statement does. } else // if the if statement returns false this loop is executed { System.out.print (character); // the Systme prints out a character } } System.out.println (""); //prints a new line which is blank. } }}