Complete the code to define a method that prints a greeting.
public void [1]() { Console.WriteLine("Hello, friend!"); }
The method name should be Greet to match the greeting action.
Complete the code to call the method that prints a greeting.
class Program { static void Main() { [1](); } static void Greet() { Console.WriteLine("Hello, friend!"); } }
You call the method by its name Greet to print the greeting.
Fix the error in the method definition by completing the missing return type.
public [1] Greet() { Console.WriteLine("Hello!"); }
The method does not return a value, so its return type must be void.
Fill both blanks to define and call a method that adds two numbers and returns the result.
public static int Add(int a, int b) {
return a [1] b;
}
static void Main() {
int sum = Add(3, 4);
Console.WriteLine(sum [2] 0);
}The method adds two numbers using '+'. The Console.WriteLine checks if sum is greater than 0 using '>'.
Fill all three blanks to define a method that checks if a number is even and call it in Main.
public static bool IsEven(int num) {
return num [1] 2 [2] 0;
}
static void Main() {
bool result = IsEven([3]);
Console.WriteLine(result);
}The method uses '%' to get remainder, '==' to check equality with 0, and calls IsEven with 4.