Return values and void methods
📖 Scenario: You are creating a simple calculator program that can add two numbers and also print a greeting message.
🎯 Goal: Build a program with one method that returns the sum of two numbers and another method that prints a greeting message without returning anything.
📋 What You'll Learn
Create a method called
AddNumbers that takes two integers and returns their sum.Create a method called
PrintGreeting that prints a greeting message and returns nothing (void).Call both methods from the
Main method and display the sum.💡 Why This Matters
🌍 Real World
Methods that return values and void methods are common in all software programs to organize code and perform tasks.
💼 Career
Understanding how to write and use methods is essential for any programming job, as it helps create reusable and clear code.
Progress0 / 4 steps