For Loop Questions

1. What does the following code output?

for (int i = 0; i< 10; i++)

        {  for (int j = 0; j <10; j++)

           { System.out.print(1*j %10);

           }

           System.out.println();

        }

 

2. What does the following code output?

for (int i = 0; i< 5; i++)

        {  for (int j = 0; j <5; j++)

           { System.out.print(i*j %10);

           }

           System.out.println();

        }

 

3. How often do the following loops execute?

(a)    for (i = 1; i <= 10; i++)

(b)   for (i = 0; i < 10; i++)

(c)    for (i = 10; i > 0; i--)

(d)   for (i= -10; i <= 10; i++)

(e)    for (i= 10; i>=0; i++)

(f)     for (i=-10; i <= 10; i=i+2)

(g)    for (i=-10; i<=10;i=i+3)

 

4. Rewrite the following for loop into a while loop

int s = 0;

for (int i = 1; i<=10; i++)

{s = s+i;

}