Java nested for loop programming example?

 

Java nested for loop programming example:-

§  Syntax  nested for loop:-

for (int  i=1; i< 100; i++)    {

for  (int  j=1; j<=10; j++);   {

//statement

}

}

Q.p] write a program to print star     * ?

class    StarPrint  {

public static void main(String  args[])   {

int  i, j;

for (int  i=1; i<=5; i++)    {

for  (int  j=1; j<=i; j++);   {

System.out.println(“*”);

}

System.out.println(“ ”);

}

}

}

Q.p] write a program to print numbere      1?

class    Number  {

public static void main(String  args[])   {

int  i, j;

for (int  i=1; i<=5; i++)    {

for  (int  j=1; j<=i; j++);   {

System.out.println(j+ “ ”);

}

System.out.println(“ ”);

}

}

}

Q.p] write a program to print numbere      1 to 15 with piramid?

class    Number  {

public static void main(String  args[])   {

int  i, j, k;

for (int  i=1; i<=5; i++)    {

for  (int  j=1; j<=i; j++);   {

System.out.println(k);

k ++;

}

System.out.println(“ ”);

}

}

}

 


 

Post a Comment

0 Comments