/**
* user inputs a number greater than 2
*/
/**
run:
Enter an even number : 4
*
* *
* *
* *
* *
* *
*
*/
/*
* No negative inputs please
*/
/**
* A quote: there are more than one ways to do it
*/
package javaapplication2;
import java.util.Scanner;
/**
*
* @author Umang
*/
public class Main
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
boolean b = false;
// to print inner stars
int n1 = 0;
int n2 = 0;
// loop variables
int j = 0, k = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter an even number : ");
int n = s.nextInt();
n1 = n2 = n / 2 + 1;
System.out.print("\n");
for (j = 0; j <= n +2 ; j++)
{
for (k = 0; k < n * 2; k++)
{
if (k == n1 || k == n2)
{
System.out.print( " * " );
}
else
{
System.out.print(" ");
}
}
if(j-1==n/2)
{
b = true;
}
if (b == false)
{
n1--;
n2++;
}
else
{
n1++;
n2--;
}
System.out.print("\n");
}
}
}
Sunday, March 13, 2011
Pattern Program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment