Desafio: Valores de Retorno
Here operate is a method which is supposed to return true if a + b equals c. Fill in the blank to make the method behave accordingly.
main.cs
12345678910111213141516171819using System; namespace ConsoleApp { internal class Program { static __ operate(int a, int b, int c) { __; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }
- We can write expressions directly in the return statement.
- For-example, writing
return a + b; is valid as it will first evaluatea + band in-turn return the resultant value. Similarly, we can also directly write boolean expressions in the return values, as boolean expressions are expressions after all. Hence, writingreturn a > b; is also valid. Using this information, think of a way how you can write a boolean expression that returnstrueif the sum ofaandbis greater thanc.
main.cs
12345678910111213141516171819using System; namespace ConsoleApp { internal class Program { static bool operate(int a, int b, int c) { return (a + b) == c; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 6. Capítulo 7
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 1.59
Desafio: Valores de Retorno
Deslize para mostrar o menu
Here operate is a method which is supposed to return true if a + b equals c. Fill in the blank to make the method behave accordingly.
main.cs
12345678910111213141516171819using System; namespace ConsoleApp { internal class Program { static __ operate(int a, int b, int c) { __; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }
- We can write expressions directly in the return statement.
- For-example, writing
return a + b; is valid as it will first evaluatea + band in-turn return the resultant value. Similarly, we can also directly write boolean expressions in the return values, as boolean expressions are expressions after all. Hence, writingreturn a > b; is also valid. Using this information, think of a way how you can write a boolean expression that returnstrueif the sum ofaandbis greater thanc.
main.cs
12345678910111213141516171819using System; namespace ConsoleApp { internal class Program { static bool operate(int a, int b, int c) { return (a + b) == c; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 6. Capítulo 7