# Re: Nested for loops

• February 21st, 2013, 01:12 PM
capt_jaggy
Re: Nested for loops
my output its come like
1
1
1
1
1
2
2
2
2
2
3
3
3
3........
pls help I cant find wht problem there in the codeing

--- Update ---

my output its come like
1
1
1
1
1
2
2
2
2
2
3
3
3
3........
pls help I cant find wht problem there in the codeing
• February 21st, 2013, 01:18 PM
Norm
Re: Nested for loops
Please post the code you are using and wrap your code with
[code=java]
[/code]
to get highlighting and preserve formatting.
• February 23rd, 2013, 03:11 AM
capt_jaggy
Re: Nested for loops
Quote:

Originally Posted by Norm
Please post the code you are using and wrap your code with
[code=java]
[/code]
to get highlighting and preserve formatting.

import java.util.Scanner;
class jag23
{
public static void main(String args[])
{
int n,num=1,c,d;
Scanner in=new Scanner(System.in);
System.out.println("Enter the number of rows of floyd's triangle you want");
n=in.nextInt();
System.out.println("Floyd's triangle");
for(c = 1;c <= n;c++)
{
for(d = 1;d <= c;d++)
{
System.out.println(+num);
num++;
}
System.out.println();

}
}
}
• February 23rd, 2013, 06:40 AM
Norm
Re: Nested for loops
[code=java]
[/code]
to get highlighting and preserve formatting.

Make sure the code is properly formatted with indentations.
• February 28th, 2013, 05:48 AM
Tamilarasi
Re: Nested for loops
Actually you made mistake on print statement.That is ,

Code :

`System.out.println(+num);`

you use "println". So "ln" means each time iterate the loop print statement is print next line.
so that the output given only vertically

So you used print instead of println like this..

Code :

`System.out.print(+num);`

this will print the correct Floyd's triangle.
• March 8th, 2013, 04:15 AM
depsai
Re: Nested for loops
loop within loop

--- Update ---

2
2
2
2
2
3
3
3
3........
pls help I cant find wht problem there in the codeing[/QUOTE]
• March 18th, 2013, 05:21 AM
Arun Kumar
Re: Nested for loops
what type of out put u want