Nested for loop pattern H and N

package Forloopbase;

public class Forloop {

public static void main(String[] args) {
//pattern();
//pattern1();
//patternH();
patternN();
// TODO Auto-generated method stub

}
private static void patternN() {
// TO…


This content originally appeared on DEV Community and was authored by hema latha

package Forloopbase;

public class Forloop {

public static void main(String[] args) {
    //pattern();
    //pattern1();
    //patternH();
    patternN();
    // TODO Auto-generated method stub

}
private static void patternN() {
// TODO Auto-generated method stub
for(int line = 1; line<=9; line++)
{
for(int col=1; col<=9; col++)
{
if( col == 1 ||col==9 || line==col)
System.out.print("* ");
else

                System.out.print("  ");}
System.out.println();

}}

private static void patternH() {
    // TODO Auto-generated method stub
    for(int line = 1; line<=9; line++)
    {
        for(int col=1; col<=9; col++)
        {
if(  col == 1 ||col==9 ||line==5 )
            System.out.print("* ");
        else 

                System.out.print("  ");}
System.out.println();

}}
private static void pattern1() {
    // TODO Auto-generated method stub
    for(int line = 1; line<=9; line++)
    {
        for(int col=1; col<=9; col++)
        {
if( line==1 || line==9 || col == 1 ||col==9 ||line==col |line+col==10)
            System.out.print("* ");
        else 

                System.out.print("  ");}
System.out.println();
            }}

private static void pattern() {
    // TODO Auto-generated method stub
     for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
                {System.out.print(" * ");}
            System.out.println();
        }}}

output=

  • *
  • *
  • *
  • * * * * * * * * * *
  • *
  • *
  • *
  •           * 
    
  •           * 
    


This content originally appeared on DEV Community and was authored by hema latha


Print Share Comment Cite Upload Translate Updates
APA

hema latha | Sciencx (2025-02-13T04:42:20+00:00) Nested for loop pattern H and N. Retrieved from https://www.scien.cx/2025/02/13/nested-for-loop-pattern-h-and-n/

MLA
" » Nested for loop pattern H and N." hema latha | Sciencx - Thursday February 13, 2025, https://www.scien.cx/2025/02/13/nested-for-loop-pattern-h-and-n/
HARVARD
hema latha | Sciencx Thursday February 13, 2025 » Nested for loop pattern H and N., viewed ,<https://www.scien.cx/2025/02/13/nested-for-loop-pattern-h-and-n/>
VANCOUVER
hema latha | Sciencx - » Nested for loop pattern H and N. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/13/nested-for-loop-pattern-h-and-n/
CHICAGO
" » Nested for loop pattern H and N." hema latha | Sciencx - Accessed . https://www.scien.cx/2025/02/13/nested-for-loop-pattern-h-and-n/
IEEE
" » Nested for loop pattern H and N." hema latha | Sciencx [Online]. Available: https://www.scien.cx/2025/02/13/nested-for-loop-pattern-h-and-n/. [Accessed: ]
rf:citation
» Nested for loop pattern H and N | hema latha | Sciencx | https://www.scien.cx/2025/02/13/nested-for-loop-pattern-h-and-n/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.