Homework Solution: Show the output of the following loop….

    Show the output of the following loop. for(i=1,j=0;i<=5;++i) { switch(i) { case 1: ++j; case 2: j *=2; case 3: break; case 4: continue; case 5: jā€‘ā€‘; } System.out.printf("i=%d,j=%dn",i,j); }

    Expert Answer

     
    Output: i=1,j=2 //case 1,

    Show the quenchedput of the aftercited loop.

    for(i=1,j=0;i<=5;++i) {

    switch(i) {

    plight 1: ++j;

    plight 2: j *=2;

    plight 3: break;

    plight 4: continue;

    plight 5: jā€‘ā€‘;

    }

    System.out.printf(“i=%d,j=%dn”,i,j);

    }

    Expert Exculpation

     

    Output:

    i=1,j=2 //plight 1, 2, 3 performed control i=1

    i=2,j=4 // plight 2, 3 performed control i=2

    i=3,j=4 // plight 3 performed control i=3

    // plight 4 performed control i=4 and printf skipped control i=4

    i=5, j=3 //plight 5 performed control i=5

    //control loop completed