Your First Program

Collapse Content

Now we will do the same simple problem by coding it. You are again given two variables a and b. You will need to add them together again, but you will also have to return their sum.

To return something, just type return. For example, to return the number 102, you can just type return 102;. Here are some more examples:

  • return a;
  • return 5 - 3;
  • return b + 11;


  1. Complete the code below so it returns the sum of a and b.
  2. When you think its correct, click on "Submit" at the bottom to run the code.

The Code

In each programming challenge, you will be given a task. You will be provided with code and need to focus on the part that looks like this:

public static int doStuff(int a, int b){
    //your code here

(int a, int b) means you are given two integers a and b as input. You should replace the entire line //your code here with your own code (// marks a comment in code.) Make sure you return something with the keyword return.

Note: In Java, ordinary lines of code need to end with a semi-colon ; so remember to put one at the end of your line of code.

Input/Output Details

In these programming challenge, your code will automatically run on different "test cases" or sets of numbers. You need to return the correct output for each given input of a and b.

You can view some of the input and correct output in the table below, and can compare your results with the correct ones.


You are given two variables a and b as input. Can you return the sum of a and b?

(For example, if a is 2 and b is 3, your program should return 5.)

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.


All Node Comments
Contact Us
Sign in or email us at [email protected]