Java programming question.

Associate
Joined
8 Oct 2006
Posts
1,236
Hi all,

Revising for my course and got a question that Im not sure about:

Given the following java program segment

_______for (int i=0;i < n-2;i++)
_________for (int j=i+1;j < n-1; j++)
__________for (int k=j+1; k < n; k++)
_____________System.out.println(i + “ “ + j + “ “ k);

Q.how many times is the print statement executed? Explain your answer.


Can anyone here help me understand this please?

Thanks:)
 
Last edited:
hi thanks for that, looks confusing!

n is definetly not given!

ran it thru the compiler with some values of n:

n = 0 output = 0
n = 1 output = 0
n = 2 output = 0
n = 3 output = 1
n = 4 output = 4
n = 5 output = 10
n = 6 output = 20
n = 7 output = 35

still not getting it.
 
Last edited:
Back
Top Bottom