Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)
Java Program To Print Diamond Star Pattern | Programs
Latest :

Java Program To Print Diamond Star Pattern | Programs

Java program to print diamond star pattern program. We have written the below print/draw diamond asterisk/star pattern program in four different ways with sample example and output do check it out. At the end of the program, we added compiler such that you can execute the below codes – Also check Number pattern Programs in Java.

  • Print Diamond star pattern program – Using For Loop
  • Print – Using While Loop
  • print – Using Do While Loop

1. Using For Loop – Diamond Star / Asterisk Pattern Code

The explanation for the above code:

1) For loop is useful when the set of statements need to execute N no. at times.

2) First outer for loop displays half of the diamond pattern, 2nd outer for loop displays the remaining half of the pattern.

3) First outer for loop executes the code until the condition false if the condition at for loop true it checks the 1st inner loop condition if true its display space, if false it comes to 2nd inner loop and checks the condition,  if true it display charter “*” / Asterisk

3) cursor comes to next line, 2nd outer for loop will execute the code until the condition false. In 2nd outer for loop if the condition true then it checks condition at 1st inner loop if condition true then it displays space otherwise it goes to 2nd inner loop and checks the condition if true then it displays the charter”*”.

4) The second outer for loop will display this pattern.

Output:

2. Using While Loop

1) while loop is entry checking loop,i.e it checks the code at while, if it is true it executes the code.

2) The 1st outer while loop executes the code until the condition i<=n false. if the condition true it checks the 1st inner while loop if condition true then it displays space, otherwise, goes to the next inner loop and display charter “*”.

3) 2nd outer while loop executes the code until the condition I>0.

Output:

 

3. Diamond Star Pattern Program – Using Do While Loop

  1. The do-while loop is exit checking loop,i.e it executes the code once then checks the condition.

2) 1st outer do-while loop executes the statements until the condition ++i<=n is false,the first inner loop will display space until the condition ++j<=n-i+1 is false, 2nd inner loop will display “*” until the condition++j<=i*2-1 is false. The 1st outer do-while loop will display half of the diamond pattern.

3) The 2nd outer do-while loop will execute the statements until the condition –i>0 if false. The 1st inner loop will display space until the condition ++j<=n-i+1 is false,The 2nd inner loop will display charter “*” until the condition ++j<=i*2-1 is false.The 2nd outer do-while loop will display the remaining half of the pattern of the diamond.

Output:
That’s it.

You can learn Star Pattern Programs in Java Here.

Other Programs In Java:

x

Check Also

LCM Of Two Numbers Java Program | 5 Ways – Programs

Java program to find the LCM of two numbers – In the below-mentioned java programs, ...

bakırköy escortşişli escortsightcareDeneme Bonusu Veren SitelerDeneme Bonusu Veren SitelerDeneme Bonusu Veren SitelerDeneme Bonusu Veren Sitelerdeneme bonusu veren sitelergrandpashabetgrandpashabetGrandpashabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelercasinofastbetwoondeneme bonusu veren sitelerdeneme bonusugrandpashabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerromabetgrandpashabetgrandpashabetgrandpashabetbetgray güncel girişgrandpashagrandpashabetgrandpashabetgrandpashabet güncel girişgrandpashadeneme bonusu veren sitelerDeneme Bonusu Veren SitelerjojobetbetovisenobahiscasinowonDubai escortBetpas girişholiganbet güncel girişbahiscasinojojobetbetgray güncelmatbet girişholiganbetholiganbetjojobetcasibomgrandpashabetgrandpashabetgrandpashabet güncel adresgrandpashacasibompusulabetjojobetmatbetpadişahbetpadişahbetmeritkinggrandpashabetgrandpashaCasibomultrabetmatbethalkalı escortmatbettürk ifşacasibomcasibomcasibomcasibomcasibom girişcasibom girişcasibom girişPadişahbetcasibom girişcasibomcasibombahisfairbahisfairmatbet 2025matbetenobahiscasibombetnanobetcioholiganbetotobetotobetsakarya escortBetpasBetpas girişnakitbahisnakitbahisvaycasino girişkingroyalkingroyalmadridbetmadridbetSheratonbetsheratonbetdermocasibom giriş deneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerromabetmarsbahissora watermark removermarsbahiscasinoroyalSekabetjojobetgrandpashabetmeritking girişsekabet girişmatbetpusulabetvaycasinograndpashabet girişmeritkinggrandpashabet girişpusulabetjojobetmeritkingholiganbetsuperbetartemisbetasyabahismeritkingsuperbetbahsinegrandpashabetartemisbetgalabetasyabahismatadorbet girişholiganbet,holiganbet giriş,holiganbet güncel girişholiganbetbetebetmeritkingmeritkinggrandpashabet girişasyabahismeritking girişmarsbahisholiganbetgrandbetting girişcasibom girişholiganbetholiganbet girişjojobetjojobetbetnano girişmatbetcasibombetnanokulisbetwbahisjokerbetHoliganbetNakitbahismarsbahisparibahispashagamingpashagamingultrabetcasibom girişcasibomgalabetbetciocasibom girişsolibetsolibet girişsolibet giriş adresisolibetsolibetcasibomcratosroyalbetcratosroyalbet girişmarsbahistaraftarium24