Function returning a value - Practice Exercises Java Lesson 5: Functions Exercise 5.3: Function returning a value Objetive: Create a program whose Main must be like this: public static void Main() { int x= 3; int y = 5; Console.WriteLine( Sum(x,y) ); } "Sum" is a function that you must define and that will be called from inside Main. As you can see in the example, it must accept two integers as parameters, and it must return an integer number (the sum of those two numbers). Source Code: JAVA C# public class Main { public static int Sum(int a, int b) { int result; result = a + b; return result; } public static void main(String[] args) { int x = 3; int y = 5; System.out.println(Sum(x, y)); } } Copy Exercise to ClipBoard Copy Code to ClipBoard Exercisey 5.3
More exercises for Lesson 5 Previous Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 Next >>