import java.util.Scanner;
/***************************************************************
* Robert Allen : Java 111a *
* *
* Parallelogram Program: Output a parallelogram with border *
* and size defined by the user. *
* *
***************************************************************/
public class Parallelogram
{
public static void main(String[] args)
{
int size, slope; //We can make it bigger.
String gimmie; //For user input. We will pull the first character for the parallelogram.
char what; //The character to be used to make the parallelogram.
Scanner scan = new Scanner(System.in);
System.out.println("This program will output a parallelogram."); //User input section of code.
System.out.print("How long do you want each side to be? ");
size = scan.nextInt();
scan.nextLine();
System.out.print("What character should this thing be made of? ");
gimmie = scan.next();
what = gimmie.charAt(0);
System.out.println();
for(int i = 1; i <= size; i++) //Output for top half of parallelogram.
{
for(int j = 1; j < (i+1); j++)
{
if(j==1 || j==i)
System.out.print(what);
else
System.out.print(" ");
}
System.out.print("\n");
}
//Output for lower half of parallelogram.
slope = 2; //Tells the program where on the x axis to start.
for (int k = 1; k < size; k++)
{
for (int m = 1; m <= size; m++)
{
if (m == slope || m == size)
{
System.out.print (what);
}
else
{
System.out.print (" ");
}
}
System.out.print ("\n");
slope++;
}
System.out.println();
}
}
/*
Sample Outputs:
[rallen1@hills ~]$ java Parallelogram
This program will output a parallelogram.
How long do you want each side to be? 3
What character should this thing be made of? &
&
&&
& &
&&
&
[rallen1@hills ~]$ java Parallelogram
This program will output a parallelogram.
How long do you want each side to be? 5
What character should this thing be made of? #
#
##
# #
# #
# #
# #
# #
##
#
[rallen1@hills ~]$ java Parallelogram
This program will output a parallelogram.
How long do you want each side to be? 9
What character should this thing be made of? *
*
**
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
**
*
*/
syntax highlighted by Code2HTML, v. 0.9