import [Link].
Scanner;
class Pattern_printer {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("PATTERN PRINTING - Version 1");
int choice;
do {
// Number of characters
[Link]("Enter number of characters:");
int charCount = [Link]();
char[] a = new char[charCount];
// Input characters
[Link]("Enter " + charCount + " characters:");
for (int i = 0; i < charCount; i++) {
a[i] = [Link]().charAt(0);
}
// Number of rows
[Link]("Enter number of rows:");
int rows = [Link]();
// Upper half pattern
for (int i = 1; i <= rows / 2; i++) {
for (int j = 0; j < i; j++) {
[Link](a[j % charCount] + " ");
}
[Link]();
}
// Lower half pattern
for (int i = rows / 2 - 1; i >= 1; i--) {
for (int j = 0; j < i; j++) {
[Link](a[j % charCount] + " ");
}
[Link]();
}
[Link]("Enter 1 to continue or 0 to exit:");
choice = [Link]();
} while (choice != 0);
[Link]("Exiting... Thank you!");
[Link]();
}
}
import [Link];
class DiamondPattern {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of characters: ");
int n = [Link]();
char[] a = new char[n];
[Link]("Enter characters:");
for (int i = 0; i < n; i++) {
a[i] = [Link]().charAt(0);
}
[Link]("Enter number of rows: ");
int rows = [Link]();
for (int i = 1; i <= rows; i++) {
for (int s = 1; s <= rows - i; s++)
[Link](" ");
for (int j = 0; j < i; j++)
[Link](a[j % n] + " ");
[Link]();
}
for (int i = rows - 1; i >= 1; i--) {
for (int s = 1; s <= rows - i; s++)
[Link](" ");
for (int j = 0; j < i; j++)
[Link](a[j % n] + " ");
[Link]();
}
[Link]();
}
}
import [Link];
class PatternPrinterMenu {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int choice;
do {
[Link]("\nPATTERN PRINTER MENU");
[Link]("1. Right Triangle");
[Link]("2. Inverted Triangle");
[Link]("3. Pyramid");
[Link]("4. Diamond");
[Link]("0. Exit");
[Link]("Enter your choice: ");
choice = [Link]();
if (choice == 0)
break;
[Link]("Enter number of characters: ");
int n = [Link]();
char[] a = new char[n];
[Link]("Enter " + n + " characters:");
for (int i = 0; i < n; i++) {
a[i] = [Link]().charAt(0);
}
[Link]("Enter number of rows: ");
int rows = [Link]();
switch (choice) {
// Right Triangle
case 1:
for (int i = 1; i <= rows; i++) {
for (int j = 0; j < i; j++) {
[Link](a[j % n] + " ");
}
[Link]();
}
break;
// Inverted Triangle
case 2:
for (int i = rows; i >= 1; i--) {
for (int j = 0; j < i; j++) {
[Link](a[j % n] + " ");
}
[Link]();
}
break;
// Pyramid
case 3:
for (int i = 1; i <= rows; i++) {
for (int s = 1; s <= rows - i; s++) {
[Link](" ");
}
for (int j = 0; j < i; j++) {
[Link](a[j % n] + " ");
}
[Link]();
}
break;
// Diamond
case 4:
for (int i = 1; i <= rows; i++) {
for (int s = 1; s <= rows - i; s++) {
[Link](" ");
}
for (int j = 0; j < i; j++) {
[Link](a[j % n] + " ");
}
[Link]();
}
for (int i = rows - 1; i >= 1; i--) {
for (int s = 1; s <= rows - i; s++) {
[Link](" ");
}
for (int j = 0; j < i; j++) {
[Link](a[j % n] + " ");
}
[Link]();
}
break;
default:
[Link]("Invalid choice!");
}
} while (true);
[Link]("Program Ended.");
[Link]();
}
}