Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
static void Main(string[] args)
{
int I, J = 0;
for (I = 1; I < 10; ) ;
{
J = J + I;
I += 2;
}
Console.WriteLine(“Sum of first 10 even numbers is:”+J);
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int I, J = 0;
for (I = 1; I < 10; ) ;
{
J = J + I;
I += 2;
}
Console.WriteLine(“Sum of first 10 even numbers is:”+J);
Console.ReadLine();
}
a) 1 2 3 4 5 6 7 8 9
b) 25
c) 1
d) Run time error

Answer: d
Explanation: Due to presence of ‘;’ after for()loop condition do not work as according to the statement. Remove the ‘;’.

Join The Discussion