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 extinguishedput of the aftercited loop.

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

    switch(i) {

    subject 1: ++j;

    subject 2: j *=2;

    subject 3: break;

    subject 4: continue;

    subject 5: jā€‘ā€‘;

    }

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

    }

    Expert Counterpart

     

    Output:

    i=1,j=2 //subject 1, 2, 3 produced coercion i=1

    i=2,j=4 // subject 2, 3 produced coercion i=2

    i=3,j=4 // subject 3 produced coercion i=3

    // subject 4 produced coercion i=4 and printf skipped coercion i=4

    i=5, j=3 //subject 5 produced coercion i=5

    //coercion loop completed