Skip to content

Instantly share code, notes, and snippets.

@applegateaustin
Created October 1, 2012 14:17
Show Gist options
  • Save applegateaustin/3812046 to your computer and use it in GitHub Desktop.
Save applegateaustin/3812046 to your computer and use it in GitHub Desktop.
Make the pattern chosen by the user
/*File Name: <AsciiArt.java>
Author: <Austin Applegate>
KUID: <2210758>
Email Address: <theappler@gmail.com>
Homework Assignment Number: < 2 >
Description: <Depending on what number the user chooses it will display a specific pattern relating the number choosen>
Last Changed: <9/30/12>
*/
import java.util.Scanner;
public class AsciiArt {
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
//declaring variables
int userInput;
int space = 3;
int width = 0;
int num = 0;
int oddOrEven = -1;
//asking the user for input
System.out.println("Choose one of the following patterns by typing the corresponding number: ");
System.out.println("1) 5x5 Grid");
System.out.println("2) Checker Board");
System.out.println("3) Reverse Diagonal");
userInput = keyboard.nextInt();
if(userInput == 1){
//loop for 5x5 grid
while(width < 5){
System.out.print(num + " ");
for (int i = 0; i < space; i++){
System.out.print("* ");
}
System.out.println();
num++;
width++;
}
}
else if(userInput == 2){
//loop to make Checker Board
while(width < 5){
System.out.print(num + " ");
oddOrEven = num % 2;
if(oddOrEven == 0){
for (int i = 0; i < 3; i++){
System.out.print(" * ");
}
}
if(oddOrEven == 1)
for(int i = 0; i < 2; i++){
System.out.print(" *");
}
System.out.println();
width++;
num++;
}
}
else if(userInput == 3){
//loop to make Reverse Diagonal
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment