0% found this document useful (0 votes)
70 views

Asterisk Patterns Using Flow Controls (Java)

The document describes 12 different patterns for printing asterisks using flow control statements in Java. Each pattern is presented with the Java code to generate it and a sample output. The patterns demonstrate using loops and conditional statements like if-else to control the printing of asterisks in various shapes.

Uploaded by

Darshana Prabath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Asterisk Patterns Using Flow Controls (Java)

The document describes 12 different patterns for printing asterisks using flow control statements in Java. Each pattern is presented with the Java code to generate it and a sample output. The patterns demonstrate using loops and conditional statements like if-else to control the printing of asterisks in various shapes.

Uploaded by

Darshana Prabath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Flow Controls

(Asterisk patterns using Flow Controls)

Content

Pattern
Pattern
Pattern
Pattern
Pattern
Pattern
Pattern
Pattern
Pattern
Pattern
Pattern
Pattern

01
02
03
04
05
06
07
08
09
10
11
12

Pattern 01
class Pattern1{
public static void main(String[] args){

int n = 10;
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
System.out.print("*");
}
System.out.println("*");
}
}
}

Output :

Pattern 02
class Pattern2{
public static void main(String[] args){

int n = 10;
for(int i = 0; i < n; i++){
for(int j = i; j < (n-1); j++){
System.out.print("*");
}
System.out.println("*");
}
}
}

Output :

Pattern 03
class Pattern3{
public static void main(String[] args){

int n = 10;
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
System.out.print("*");
}
System.out.println("*");
if(i == (n-1)){
while(i != 0){
i--;
for(int j = 0; j < i; j++){
System.out.print("*");
}
System.out.println("*");
}
break;
}
}
}
}

Output :

Pattern 04
class Pattern4{

public static void main(String[] args){


int n = 10;
for(int i = 0; i < n; i++){
for(int j = i; j < (n-1); j++){
System.out.print("*");
}
System.out.println("*");
if(i == (n-2)){
while(i != 0){
i--;
for(int j = i; j < (n-1); j++){
System.out.print("*");
}
System.out.println("*");
}
break;
}
}
}
}

Output :

Pattern 05
class Pattern5{

public static void main(String[] args){


int n = 10;
for(int i = 0; i < n; i++){
for(int j = i; j < (n-1); j++){
System.out.print(" ");
}
for(int j = 0; j < (2*i); j++){
System.out.print("*");
}
System.out.println("*");
}
}
}

Output :

Pattern 06
class Pattern6{

public static void main(String[] args){


int n = 10;
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
System.out.print(" ");
}
for(int j = (2*i); j < ((2*n)-2); j++){
System.out.print("*");
}
System.out.println("*");
}
}
}

Output :

Pattern 07
class Pattern7{

public static void main(String[] args){


int n = 10;
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
System.out.print(" ");
}
for(int j = (2*i); j < ((2*n)-2); j++){
System.out.print("*");
}
System.out.println("*");
if(i == (n-1)){
while(i != 0){
i--;
for(int j = 0; j < i; j++){
System.out.print(" ");
}
for(int j = (2*i); j < ((2*n)-2); j++){
System.out.print("*");
}
System.out.println("*");
}
break;
}
}
}
}

Output :

Pattern 08
class Pattern8{

public static void main(String[] args){


int n = 10;
for(int i = 0; i < n; i++){
for(int j = i; j < (n-1); j++){
System.out.print(" ");
}
for(int j = 0; j < (2*i); j++){
System.out.print("*");
}
System.out.println("*");
if(i == (n-1)){
while(i != 0){
i--;
for(int j = i; j < (n-1); j++){
System.out.print(" ");
}
for(int j = 0; j < (2*i); j++){
System.out.print("*");
}
System.out.println("*");
}
break;
}
}
}
}

Output :

Pattern 09
class Pattern9{

public static void main(String[] args){


int n = 10;
for(int i = 0; i < n; i++){
for(int j = i; j < (2*(n-1)); j++){
System.out.print(" ");
}
for(int j = 0; j < (2*i); j++){
System.out.print("*");
}
System.out.println("*");
if(i == (n-1)){
while(i != 0){
for(int j = i; j < (n-1); j++){
System.out.print(" ");
}
for(int j = 0; j < (2*i); j++){
System.out.print("*");
}
for(int k = 0; k < (2*(n-1)); k++){
System.out.print("*");
}
i--;
System.out.println("*");
}
break;
}
}
}
}

Output :

Pattern 10

class Pattern10{
public static void main(String[] args){
int n = 10;
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
System.out.print(" ");
}
System.out.println("*");
if(i == (n-1)){
while(i != 0){
i--;
for(int j = 0; j < i; j++){
System.out.print(" ");
}
System.out.println("*");
}
break;
}
}
}
}

Output :

Pattern 11

class Pattern11{
public static void main(String[] args){
int n = 10;
for(int i = 0; i < n; i++){
for(int j = i; j < (n-1); j++){
System.out.print(" ");
}
System.out.print("*");
for(int j = 0; j < (2*i); j++){
System.out.print(" ");
}
System.out.println("\b*");
}
}
}

Output :

Pattern 12

class Pattern12{
public static void main(String[] args){
int n = 5;
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
System.out.print(" ");
}
if(i == (n-1)){
for(int k = 0; k < ((10*n)+2); k++){
System.out.print("*");
}
for(int k = -1; k < i; k++){
System.out.print("*");
}
System.out.println();
while(i != 0){
i--;
for(int j = 0; j < i; j++){
System.out.print(" ");
}
for(int j = 0; j < (n-1); j++){
System.out.print("** ");
}
for(int k = 0; k < (8*n); k++){
System.out.print(" ");
}
for(int k = -1; k < i; k++){
System.out.print("*");

}
System.out.println();
}
break;
}
for(int j = 0; j < (n-1); j++){
System.out.print("** ");
}
for(int k = 0; k < (8*n); k++){
System.out.print(" ");
}
for(int k = -1; k < i; k++){
System.out.print("*");
}
System.out.println();
}
}
}

Output :

******************************************************************************

You might also like