Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. This statement lets the value of a variable(int or char type only) or express

ID: 3551397 • Letter: 1

Question

1. This statement lets the value of a variable(int or char type only) or expression determine where the program will branch to. a.Select b.associative c.scope d.switch
2.What will following segment of code output? 3. Which of the following are valid case statements in a switch? a. case 'ab': b.case x < 4: c.case 1: d. case 1.5:

a. case 'ab': b.case x < 4: c.case 1: d. case 1.5: 4. What is the output of the following code fragment? int i = 2;
switch(i + 1){
    case 0: i = 15; break;
    case 1: i = 25; break;
    case 2: i = 35; break;
    case 3: i = 40; break;
    default: i = 0;
}
System.out.println( i );

5. After execution of the following code, what will be the value of input_value? 7. What is the final value of x after the following fragment of code executes?
    int x = 0;
    do {
         x++;
    }while (x > 0);
8.What is the output of the following segment of code if 4 is input by the user when asked to enter a number?
int num, total = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number from 1 to 10: ");
num = scan.nextInt( );
switch (num)
{
    case 1:
    case 2: total = 5;
    case 3: total = 10;
    case 4: total = total + 3;
    case 8: total = total + 6;
    default: total = total + 4;
}
System.out.println( total );
9.All switch statements can be converted into nested if-else statements but all nested if-else statements cannot be converted into switch statements. Ture or False

1. This statement lets the value of a variable(int or char type only) or expression determine where the program will branch to. a.Select b.associative c.scope d.switch
2.What will following segment of code output? int x = 5;
if (x != 2)
     System,out.println( "This is true!");
else
     System.out.println( "This is false!");
     System.out.println("This is all folks!");


3. Which of the following are valid case statements in a switch? a. case 'ab': b.case x < 4: c.case 1: d. case 1.5:

4. What is the output of the following code fragment? int i = 2;
switch(i + 1){
    case 0: i = 15; break;
    case 1: i = 25; break;
    case 2: i = 35; break;
    case 3: i = 40; break;
    default: i = 0;
}
System.out.println( i );

5. After execution of the following code, what will be the value of input_value? int input_value = 0;
if (input_value > 5){
      input_value = input_value + 5;
}
else if (input_value > 2){
      input_value = input_value + 10;
}
else {
    input_value = input_value + 15;
}


6.If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false?
      if ( x < 2 && w < y)



7. What is the final value of x after the following fragment of code executes?
    int x = 0;
    do {
         x++;
    }while (x > 0);

8.What is the output of the following segment of code if 4 is input by the user when asked to enter a number?
int num, total = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number from 1 to 10: ");
num = scan.nextInt( );
switch (num)
{
    case 1:
    case 2: total = 5;
    case 3: total = 10;
    case 4: total = total + 3;
    case 8: total = total + 6;
    default: total = total + 4;
}
System.out.println( total );




9.All switch statements can be converted into nested if-else statements but all nested if-else statements cannot be converted into switch statements. Ture or False

10.What is wrong with the following for loop?
   for (int i = 0; i < 10; i -- ){
       System.out.println("Hello");
   }


Explanation / Answer

1> d > switch

2 > This is false!

This is all folks!

3> c> case 1

4> 40

5> 15

6> false

7> infinite loop, x goes on increasing

8> 13

9> true

10> infinite loop, i goes on decreasing and loop never ends