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

Hollow Diamond Star Pattern Java Program | Patterns

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

  • Using For Loop
  • Using While Loop
  • Using Do While Loop

Using For Loop

1) The first outer for loop will display the half of the hollow diamond pattern, the 2nd outer for loop will display the remaining hollow diamond pattern.

2) The 1st outer for loop executes the set of statements until the condition i<n is false, if the condition is true the 1st inner loop will be executed until the condition is true, then it checks the if condition true it will display character “*”, otherwise else part will display space.

Next 2nd inner loop will be executed until the condition is false. For i=0 the 1st row of the hollow pattern completed. 1st for loop will display this pattern.

3) The 2nd outer for loop executes the statements until the condition is false. The 1st inner loop executes the statements until the condition is false. In this loop if “if” condition is true then it displays character “*” otherwise it displays space.

The 2nd inner loop executes the set of statements until the condition is false, in the 2nd inner loop if “if” condition true it display space else it displays character “*”. The 2nd outer loop will display this pattern.

Output:

Using While Loop

1) 1st outer while loop will execute the code until the condition is true. The 1st inner while loop executes the statements until the condition j<n.

In 1st inner while loop if j<n-i is true it will display character, else it displays space.

After 1st inner loop execution, the 2nd inner loop will execute the statements until the condition j<n is false. In the 2nd inner loop, if the condition is j<i  is true, it will display space else it will display character”*”.

2) The 2nd outer while loop will execute the statements until the condition i<=n is false. The 1st inner loop executes the statements until the condition j<n is false, in this loop if “if” condition is true then displays character “*” otherwise displays space.

After first inner loop execution, the 2nd inner loop will be executed until the condition j<n is false. In this 2nd inner loop if “if” condition is true j<n-i it will display space otherwise it will display character.

Output:

Using Do-While Loop

1) The 1st outer do-while loop will executes the code until the condition i<n is false. The 1st inner loop executes until j<n is false. In 1st inner loop if j<n-i is true it will display character “*” otherwise it will display space.

2) After 1st inner loop execution, the 2nd inner loop will be executed until the condition j<n is false, in this loop if the if condition j<i true it prints space otherwise prints character “*”.

3) The 2nd outer do-while loop will be executed until the condition i<=n. The 1st inner loop execute the statements until the condition is false. In this loop, if condition j<i true then prints character otherwise prints space.

4) After completion of 1st inner loop 2nd inner loop will be executed until the condition j<i is false. The if condition j<n-i true then prints space otherwise prints the character.

Output:

For More:

List of Java Programs – More than 500+ Java Programs

x

Check Also

Reverse A Number In Java – 4 Simple Ways | Programs

Reverse A Number In Java – We have discussed the various methods to reverse a ...

atakoy escortatakoy escortbakırköy escorthalkali escortbağcılar escortsightcaredeneme bonusu veren siteleristanbul, escortromabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerDeneme Bonusu Veren Sitelercasino siteleriDeneme Bonusu Veren SitelerDeneme Bonusu Veren Sitelermatbetdeneme bonusu veren sitelergrandpashabetgrandpashabetGrandpashabetsloticadeneme bonusu veren sitelerdeneme bonusu veren sitelermeritkingbenbilmemcasibomholiganbetbahcesehir masaj salonucasibomdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelercasinofastDeneme bonusu veren sitelercasinofastdeneme bonusugrandpashabetdeneme bonusu veren sitelermarsbahis betcio girişjojobetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerromabetistanbul escortgrandpashabetgrandpashabetgrandpashabetcasibom girişgrandpashabetnakitbahismadridbetmadridbet girişsekabetnakitbahisnakitbahis girişotobetotobet girişkralbetkralbet girişbetciobetcioramadabetmeritkingsekabetmeritkingcasibom girişcasibomgrandpashabetroyalbetgrandpashabetdedebetcasibom girişcasibom girişcasibom girişcasibomcasibomcasibom girişMeritkinggrandpashabetpalacebetjojobet girişonwinmeritkingroyalbetgrandpashabetmeritking girişsekabetmeritkingmarsbahis giriş güncelmatbetimajbetmarsbahisimajbet güncel girişholiganbetjojobetjojobetroyalbetholiganbetelitcasinocasibommeritkingcasibomcasibom girişcasibom girişcasibomiptv satın albetparkaras kargo takipbetexper girişmatadorbet , matadorbet girişcoinbarperabet girişbetpark girişcoinbar girişcratosslotmegabahis girişsuperbetin girişbetexperperabetextrabet,extrabet girişbetparkmegabahissuperbetinbetexper girişextrabetcasibom girişcasibomcasibom girişgrandpashabetgrandpashabet girişcasibomcasibom girişvaycasinovaycasino girişcasibomcasibom girişgrandpashabetgrandpashabet girişgrandpashabetgrandpashabet girişbetparkcratosslot girişbetgray güncel girişjojobetgrandpashabetgrandpashabetgrandpashabetgrandpashabetgrandpashabetMeritkingzbahis giriş güncelcasibom girişcasibom girişcasibomroyalbetcasibomimajbetpusulabetjojobet girişdeneme bonusu veren sitelerHititbet GirişcasibomDeneme Bonusu Veren Sitelercasibom güncel girişcasibomcasibomcasibombahiscasinojojobetcasibomkalebet girişkalebetCasibom