adplus-dvertising
frame-decoration

Question

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).1 Only

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Which of the following code snippets are the correct way to determine whether a is Odd or Even?