Forum : value of sum in nested for loops
Brief description  about Online courses   join in Online courses
View gurdip  sahota 's Profile

value of sum in nested for loops

class Sum1{

public static void main(String[] args){
int sum=0;
for(int i=0; i<5; i ){
sum=sum i;
for(int j=0; j<5; j ){
sum=sum j;
}
}
}

}
Asked by gurdip sahota | Dec 30, 2010 |  Reply now
Replies (4)
View gurdip sahota 's Profile
thnaks Akhmad...spot on!!
Jan 1, 2011
View akhmad durdibayevich qutlimuratov 's Profile
Hi there, after the outer loop's end "}", u have to put the following print statement, otherwise no output:
System.out.println(sum);
Dec 31, 2010
View gurdip sahota 's Profile
oh I just saw it now... I just copy-paste code for Jcreator..but it came out with missing '+' signs... don know why????
well my question is when i compile below code. it compiles fine, run fine but no output. here i m writing code again:-
class Sum1{

public static void main(String[] args){
int sum=0;
for(int i=0; i<5; i++ ){
sum=sum +i;
for(int j=0; j<5; j++ ){
sum=sum +j;
}
}
}

}

why is so?
Dec 30, 2010
View akhmad durdibayevich qutlimuratov 's Profile
what's your question mate? I think you forget to put your question :), anyway the answer probably will be like that below:
1) sum = sum + i 2) sum = sum + j, u forget to put "+" (addition) sign
Dec 30, 2010