Results 1 to 4 of 4
Thread: nested for loop!
- 01-21-2014, 09:07 PM #1
Member
- Join Date
- Oct 2013
- Posts
- 10
- Rep Power
- 0
nested for loop!
im trying to print this figure !!! Is there anyone that can help me in how to get the missing lines in the right of the triangle? i went to youtube and some other websites, but i wasn't able to find one that shows how to do those lines in the right side of the triangle!!
-----1-----
----333----
---55555---
--7777777--
-999999999-
but i keep getting this !
-----1
----333
---55555
--7777777
-999999999
this is what i have so far!!!
public class Example {
public static void main (String[] args){
for (int i=1; i<=9; i=i+2)
{
for (int k=0; k < (5- i / 2); k++)
{
System.out.print("-");
}
for (int j=0; j<i; j++)
{
System.out.print(i+"");
}
System.out.println("");
}
}//end of main
}//end of class
- 01-21-2014, 11:18 PM #2
Señor Member
- Join Date
- Jan 2014
- Posts
- 184
- Rep Power
- 0
Re: nested for loop!
It'd be much easier for us to read if you put it in a code box.
I don't see why you couldn't just add another forloop after you print the numbers that is the same exact thing as your first forloop that prints the dashes. You print out the same number of dashes on both sides...
- 01-21-2014, 11:44 PM #3
Member
- Join Date
- Oct 2013
- Posts
- 10
- Rep Power
- 0
Re: nested for loop!
I didn't know that you could put them in a box code , sorry im new , i will next time!!!
and thank you so much for you help i added another for loop and it works perfectly !!!
- 01-23-2014, 07:57 PM #4
Member
- Join Date
- Jan 2014
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
how to use nested for loop
By geekgeek1 in forum New To JavaReplies: 5Last Post: 02-04-2014, 07:16 AM -
Nested loop
By Shasool in forum New To JavaReplies: 2Last Post: 10-23-2011, 06:10 PM -
Nested Loop
By sehudson in forum New To JavaReplies: 2Last Post: 03-11-2011, 04:39 AM -
can some one help me with nested loop?
By keycoffee in forum New To JavaReplies: 10Last Post: 01-25-2010, 03:49 AM -
Nested For Loop
By yuchuang in forum New To JavaReplies: 1Last Post: 07-08-2007, 02:11 PM
Bookmarks