Exercise: Control Instructions
Questions for: Control Instructions
What will be the output of the C#.NET code snippet given below?
int val;
for (val = -5; val <= 5; val++)
{
switch (val)
{
case 0:
Console.Write ("India");
break;
}
if (val > 0)
Console.Write ("B");
else if (val < 0)
Console.Write ("X");
}
A:
XXXXXIndia
B:
IndiaBBBBB
C:
XXXXXIndiaBBBBB
D:
BBBBBIndiaXXXXX
Answer: C
No answer description is available. Let's discuss.
Which of the following is the correct way to rewrite the following C#.NET code snippet given below?
int i = 0;
do
{
Console.WriteLine(i);
i+ = 1;
} while (i <= 10);
A:
int i = 0;
do
{
Console.WriteLine(i);
} until (i <= 10);B:
int i;
for (i = 0; i <= 10 ; i++)
Console.WriteLine(i);C:
int i = 0;
while (i <= 11)
{
Console.WriteLine(i);
i += 1;
}D:
int i = 0;
do while ( i <= 10)
{
Console.WriteLine(i);
i += 1;
}
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
What is the output of the C#.NET code snippet given below?
namespace ExamAdept
{
public enum color
{ red, green, blue };
class SampleProgram
{
static void Main (string[ ] args)
{
color c = color.blue;
switch (c)
{
case color.red:
Console.WriteLine(color.red);
break;
case color.green:
Console.WriteLine(color.green);
break;
case color.blue:
Console.WriteLine(color.blue);
break;
}
}
}
}
A:
red
B:
blue
C:
0
D:
1
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following is the correct output for the C#.NET program given below?
int i = 20 ;
for( ; ; )
{
Console.Write(i + " ");
if (i >= -10)
i -= 4;
else
break;
}
A:
20 16 12 84 0 -4 -8
B:
20 16 12 8 4 0
C:
20 16 12 8 4 0 -4 -8 -12
D:
16 12 8 4 0
Answer: C
No answer description is available. Let's discuss.
Discuss About this Question.
What does the following C#.NET code snippet will print?
int i = 0, j = 0;
label:
i++;
j+=i;
if (i < 10)
{
Console.Write(i +" ");
goto label;
}
A:
Prints 1 to 9
B:
Prints 0 to 8
C:
Prints 2 to 8
D:
Prints 2 to 9
Answer: A
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.