Challenge - 5 Problems
Method Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Understanding method reuse in C#
What will be the output of this C# program that uses a method to greet a user?
C Sharp (C#)
using System; class Program { static void Greet(string name) { Console.WriteLine($"Hello, {name}!"); } static void Main() { Greet("Alice"); Greet("Bob"); } }
Attempts:
2 left
💡 Hint
Look at how the method Greet is called with different names.
✗ Incorrect
The method Greet is called twice with different arguments, so it prints greetings for both Alice and Bob.
🧠 Conceptual
intermediate1:30remaining
Why use methods in programming?
Which of the following is the main reason to use methods in programming?
Attempts:
2 left
💡 Hint
Think about how methods help with code repetition.
✗ Incorrect
Methods allow you to write code once and reuse it many times, making programs shorter and easier to manage.
❓ Predict Output
advanced2:00remaining
Effect of methods on program structure
What will be the output of this C# program that uses methods to calculate and print the area of a rectangle?
C Sharp (C#)
using System; class Program { static int CalculateArea(int width, int height) { return width * height; } static void Main() { int area = CalculateArea(5, 3); Console.WriteLine(area); } }
Attempts:
2 left
💡 Hint
Multiply width and height inside the method.
✗ Incorrect
The method CalculateArea returns the product of width and height, which is 5 * 3 = 15.
🧠 Conceptual
advanced1:30remaining
How methods improve code maintenance
Which statement best explains how methods help maintain code?
Attempts:
2 left
💡 Hint
Think about how changing code in one method affects the whole program.
✗ Incorrect
When code is inside a method, fixing it once updates all uses, making maintenance easier.
❓ Predict Output
expert2:00remaining
Understanding method parameters and output
What will be the output of this C# program that uses a method with parameters and prints results?
C Sharp (C#)
using System; class Program { static void PrintSum(int a, int b) { Console.WriteLine(a + b); } static void Main() { int x = 4; int y = 7; PrintSum(x, y); PrintSum(y, x); } }
Attempts:
2 left
💡 Hint
The method adds two numbers and prints the result.
✗ Incorrect
Both calls add 4 and 7, resulting in 11 printed twice.