Java asterix pyramid


import java.util.Scanner;

/**
*
* @author blogger.victorbyte.net
* 30/08/2010
*/
public class Main {

static String outPut = "";
static int errorLimit = 0;
static Scanner userInput = null;

static int getIntegerInput() {
int value = 0;
userInput = new Scanner(System.in);
try {
value = userInput.nextInt();

} catch (Exception e) {
errorLimit++;
errorLimit();
System.out.println("Enter a integer value please." + e.getMessage());
return getIntegerInput();
}
return value;
}

static void errorLimit() {
if (errorLimit >= 6) {
System.out.println("You have enter the maximum number of allowed errors (" + errorLimit + ")"
+ "nThe System will now exit");
System.exit(0);
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int numberEntered = 0;
System.out.println("Please enter an integer [1...20]");
numberEntered = getIntegerInput();
while (numberEntered > 20 || numberEntered < 1) {
errorLimit++;
errorLimit();
System.out.println("Please enter an integer [1...20]");
numberEntered = getIntegerInput();
}
errorLimit();
if (!(numberEntered == 7)) {
for (int i = numberEntered; i > 0; i--) {
for (int y = 0; y < i; y++) {
outPut += "*";
}
outPut += "n";

}
}

if ((numberEntered % 2) == 0) {

StringBuilder outreverse = new StringBuilder(outPut);
outPut = outreverse.reverse().toString();
}

System.out.println(outPut);

}
}

This entry was posted in java and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *