Program to Print Alphabet E Star Pattern
In this article we are going to see how to print E star program. Alphabet pattern programs in java, Java pattern programs pdf, Pyramid star pattern in java are known in this pattern.
Example-1 When row value=6 ******* * * ***** * *******
Example-2: When row value=5 ****** * **** * ******
Now, let’s see the actual program to print it.
Enhancing programming skills is very important no matter what language you have chosen. So, practice frequently with these simple java programs examples and excel in coding the complex logic.
Approach:
- Enter total row and store it in an integer variable row.
- Take first for loop to print the row value and a star for each row .
- Take first inner for loop to print column value i.e., star according to condition
if ((r == 0 || r == row – 1) || (r == row / 2 && c <= row / 2)) - Then go on printing the star symbol according to loop.
JAVA Code:
Method-1: Static Star Character
import java.util.*; public class Main { public static void main(String args[]) { // taking variable for loop iteration and row . int row,r,c,d=0; //creating object Scanner s = new Scanner(System.in); // entering the number of row System.out.print ("Enter rows : "); row = s.nextInt(); //outer for loop for (r = 0; r < row; r++) { // Stars will be printed in first column System.out.print ("*"); // inner for loop for (c = 0; c < row; c++) { if ((r == 0 || r == row - 1) || (r == row / 2 && c <= row / 2)) System.out.print ("*"); else continue; } System.out.print ("\n"); } } }
Output: Enter rows : 5 ****** * **** * ******
Method-2: User Input Character
import java.util.*; public class Main { public static void main(String args[]) { // taking variable for loop iteration and row . int row,r,c,d=0; char e; //creating object Scanner s = new Scanner(System.in); // entering the number of row System.out.print ("Enter rows : "); row = s.nextInt(); // entering any random character System.out.print ("Enter character : "); e = s.next().charAt(0); //outer for loop for (r = 0; r < row; r++) { // Stars will be printed in first column System.out.print (e); // inner for loop for (c = 0; c < row; c++) { if ((r == 0 || r == row - 1) || (r == row / 2 && c <= row / 2)) System.out.print (e); else continue; } System.out.print ("\n"); } } }
Output: Enter rows : 5 Enter character : @ @@@@@@ @ @@@@ @ @@@@@@
C Code:
#include <stdio.h> int main() { int r, row, c ,d; printf("Enter rows: "); scanf("%d", &row); for (r = 0; r < row; r++) { printf("*"); for (c = 0; c < row; c++) { if ((r == 0 || r == row - 1) || (r == row / 2 && c <= row / 2)) printf("*"); else continue; } printf("\n"); } return 0; }
Output: Enter rows : 5 ****** * **** * ******
C++ Code:
#include <iostream> using namespace std; int main() { int row, r , c ,d ; cout << "Enter rows: "; cin >> row; for (r = 0; r < row; r++) { cout << "*"; for (c = 0; c < row; c++) { if ((r == 0 || r == row - 1) || (r == row / 2 && c <= row / 2)) cout << "*"; else continue; } cout << "\n"; } return 0; }
Output: Enter rows : 5 ****** * **** * ******
Try these:
- Write a program to print the following pattern in java
- Number pattern programs in java
- String pattern program in java
- 1 23 456 pattern printing in java
- Java program to print alphabet pattern of stars
- Java program to print pattern of alphabets
- Java program to print alphabet pyramid
- Write a program to print alphabet pattern in java
- Java program to print a star pattern
Related Java Star Pattern Programs: