Exercise: Control Instructions

Questions for: Control Instructions

The C#.NET code snippet given below generates ____ numbers series as output?
int i = 1, j = 1, val;
while (i < 25)
{
    Console.Write(j + " ");
    val = i + j;
    j = i;
    i = val;
}
A:
Prime
B:
Fibonacci
C:
Palindrome
D:
Odd
Answer: B
No answer description is available. Let's discuss.
Which of the following can be used to terminate a while loop and transfer control outside the loop?
  1. exit while
  2. continue
  3. exit statement
  4. break
  5. goto
A:
1, 3
B:
2, 4
C:
3, 5
D:
4, 5
Answer: D
No answer description is available. Let's discuss.
Which of the following code snippets are the correct way to determine whether a is Odd or Even?
  1. int a;
    String res; 
    if (a % 2 == 0)
        res = "Even"; 
    else 
        res = "Odd";
  2. int a; 
    String res; 
    if (a Mod 2 == 0) 
        res = "Even"; 
    else
        res = "Odd";
  3. int a;
    Console.WriteLine(a Mod 2 == 0 ? "Even": "Odd");
  4. int a; 
    String res;
    a % 2 == 0 ? res = "Even" : res = "Odd";
    Console.WriteLine(res);
A:
1, 3
B:
1 Only
C:
2, 3
D:
4 Only
Answer: B
No answer description is available. Let's discuss.
Which of the following is the incorrect form of Decision Control instruction?
A:
if (Condition1) 
{// Some statement}
B:
if (Condition1) {// Some statement} 
else {// Some statement}
C:
if (Condition1) {// Some statement} 
else {// Some statement} 
else if ( Condition2){//Some statement}
D:
if ( Condition1 ) {// Some statement} 
else if ( Condition2 ) {// Some statement} 
else {// Some statement}
Answer: C
No answer description is available. Let's discuss.
What will be the output of the C#.NET code snippet given below?
char ch = Convert.ToChar ('a' | 'b' | 'c'); 
switch (ch)
{
    case 'A': 
    case 'a':
    Console.WriteLine ("case A | case a");
    break;
    
    case 'B': 
    case 'b':
    Console.WriteLine ("case B | case b");
    break;
    
    case 'C':
    case 'c':
    case 'D':
    case 'd':
    Console.WriteLine ("case D | case d");
    break;
}
A:
case A | case a
B:
case B | case b
C:
case D | case d
D:
Compile Error
Answer: C
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz