package part2 public class SayCheese public static void mai

package part2;

public class SayCheese {

   public static void main(String[] args) {

       // loop from 0 to 12

       for( int i=0; i<12; i++){

           // print to console based on count value

           switch (i) {

               case 3: System.out.print(\"3\");

                       break;

               case 7: System.out.print(\"2\");

                       break;

               case 11: System.out.print(\"1\");

               default: System.out.print(\".\");

                       break;

           }

       }

       //print cheese to console

       System.out.println(\"...CHEESE!\");

   }

}

Solution

The table below demostrates the execution of switch statement based on the value of i, here i is a integer and the for loop executes for i=0 to 11 that is 12 times. So when the value of i is 3, 7 and 11 the output on console is 3,2 and 1. respectively. When value of i is 11 output is 1. becuase the switch case for 11 has no break statement. Otherwise single dot (.) is printed in cases other than 3, 7, 11 because defaultcase is prints( .).

So the Output at Console

...3...2...1....CHEESE!

Notice that CHEESE! is printed in same line because ln in println() is for next line on console so if we print something after CHEESE! that will be printed in next line.

i output to console
0 .
1 .
2 .
3 3
4 .
5 .
6 .
7 2
8 .
9 .
10 .
11 1
package part2; public class SayCheese { public static void main(String[] args) { // loop from 0 to 12 for( int i=0; i<12; i++){ // print to console based on
package part2; public class SayCheese { public static void main(String[] args) { // loop from 0 to 12 for( int i=0; i<12; i++){ // print to console based on

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site