Printing Swastik Symbol Character Pattern
In the previous article, we have discussed Java Program to Print Downward Arrow Mark Symbol Character Pattern
In this article we are going to see how to print the Swastik symbol character pattern.
Example-1
When Size : 5
A CDE
A C
ABCDE
C E
ABC E
Now, let’s see the actual program to print it.
Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.
Approach:
- Enter size of the pattern and store it in an integer variable
size. - Take one outer for loop to iterate the rows.
- Take one inner for loops, to iterate the columns.
- After each iteration print a newline.
Java Code to Print Swastik Symbol Character Pattern
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
// Scanner class object created to take user input
Scanner scan = new Scanner(System.in);
// variable 'size' represents number of rows
// variable 'r' and 'c' will be used to iterate rows and column
int size, r, c;
// Taking size as input from user
System.out.print("Size : ");
size = scan.nextInt();
// ASCII value taken 64
int asciiAlpha = 64;
// Outer Loop
// It will cover all throws
// After coompletion of printing one row
// It will move to next row
for (r = 1; r <= size; r++)
{
// Inner loop
// It will iterate one by one column
// and will go on printing column values
for (c = 1; c <= size; c++)
{
// This if condition represents the condition
// where the characters will be printed if condition satisfies
if (r == size / 2 + 1 || c == size / 2 + 1 || (r == 1 && c >= size / 2 + 1) || (r == size && c <= size / 2) || (c == 1 && r <= size / 2) || (c == size && r >= size / 2 + 1))
// It will print the characters
// Printing will start from character 'A'
// and will go on printing upto last column value in each row
System.out.print((char)(c + asciiAlpha));
else
// Printing space
System.out.print(" ");
}
//Prints a new line
System.out.println();
}
}
}
Output :
Size : 5
A CDE
A C
ABCDE
C E
ABC E
Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.
Related Java Character Pattern Programs: