0
What the output
for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ System.out.println(i*j);
5 Respuestas
+ 2
This code will give an error. You are missing 2 closing braces in the for loop. Also you can use the code section to execute the code and see the result for yourself.
+ 1
Hello Mr yaseer
outer loop: i = 1:
inner loop:
j = 1 //i * j = 1
j = 2 //i * j = 2
j = 3 //i * j = 3
...
j = 10//i * j = 10
outer loop: i = 2
inner loop:
i = 1 //i * j = 2
i = 2 //i * j = 4
i = 3 //i * j = 6
...
i = 10 //i * j = 20
outer loop: i = 3
inner loop:
j = 1 //i * j = 3
j = 2 //i * j = 6
j = 3 //i * j = 9
...
j = 10 //i * j = 30
And so on. The loops stops when i gets 11.
I hope this helps you how the nested loops work. To see the complete output you can run it in the code play ground.
0
import java.io.*;
// Java code to demonstrate star pattern
public class GeeksForGeeks
{
// Function to demonstrate printing pattern
public static void printTriagle(int n)
{
// outer loop to handle number of rows
// n in this case
for (int i=0; i<n; i++)
{
// inner loop to handle number spaces
// values changing acc. to requirement
for (int j=n-i; j>1; j--)
{
// printing spaces
System.out.print(" ");
}
// inner loop to handle number of columns
// values changing acc. to outer loop
for (int j=0; j<=i; j++ )
{
// printing stars
System.out.print("* ");
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 9;
printTriagle(n);
}
}
0
Avinesh what about that
0
If you close missing braces you will get table from 1-10.