Muhammad.R1
Active Member
- Joined
- Sep 8, 2007
- Messages
- 67
- Reaction score
- 1
Hey there guys , i've been doing I.T at school and we've been doing java programming with jGrasp.
But today the most awkward thing happened , I totally forgot the basic logic behind a program i wrote last year and im struggling with it for some reason. I've done the basics and just finished with string manipulation and about to move on to netbeans and just went over some pass work and have already forgotten it :S.
So basically thats the code and it prints out this triangle when 5 is entered:
*
**
***
****
*****
Now for some reason i am having a problem understanding how this for loop is working...
This is from my own understanding ( which is wrong no doubt).
The first star is printed by the first for loop because the second loop doesn't run since 0<0 doesn't work right? So "*" is printed and i becomes 1. Then it runs through again and goes through the second loop...so 0<1 ,and it prints out a "*". But , that can't be right since that would mean that the second star is printed next to the first star by the first loop so **.....but it has *...lol
Sorry , I'll probably confuse you guys too
Any help would be much appreciated thanks ^^!
P.S - If anyone knows a good website or a ebook/book (besides the school text book) to help further with java programming i'd really appreciate it.
But today the most awkward thing happened , I totally forgot the basic logic behind a program i wrote last year and im struggling with it for some reason. I've done the basics and just finished with string manipulation and about to move on to netbeans and just went over some pass work and have already forgotten it :S.
Code:
int height=scan.nextInt();
for(int i=0;i<height;i++)
{
for(int j=0;j<i;j++)
{
System.out.print("*");
}
System.out.println("*");
}
So basically thats the code and it prints out this triangle when 5 is entered:
*
**
***
****
*****
Now for some reason i am having a problem understanding how this for loop is working...
This is from my own understanding ( which is wrong no doubt).
The first star is printed by the first for loop because the second loop doesn't run since 0<0 doesn't work right? So "*" is printed and i becomes 1. Then it runs through again and goes through the second loop...so 0<1 ,and it prints out a "*". But , that can't be right since that would mean that the second star is printed next to the first star by the first loop so **.....but it has *...lol
Sorry , I'll probably confuse you guys too
Any help would be much appreciated thanks ^^!
P.S - If anyone knows a good website or a ebook/book (besides the school text book) to help further with java programming i'd really appreciate it.