IB Computer Science Unit 1
IB Computer Science Unit 2
IB Computer Science Unit 3
IB Computer Science Unit 4
IB Computer Science Unit 5
IB Computer Science Unit 6

IB Computer Science Using Methods With Arrays

IB Computer Science Learning Goals

In this IB Computer Science lesson you will be learning about:

  • How to use methods with array data structures

Passing By Reference

Java passes all primitive data types such as int, char, double and even Strings by value, however arrays and objects are a different matter. These are passed by reference.

When java passes something by reference it basically passes the memory address of the argument, so any modification made to that memory address will be reflected in the rest of the program

Here is a method that makes all the values in an array equal to zero

IB Computer Science Java Pass By Reference

Before the method is called the data stored in the array is a bunch of random numbers. After the
method is called the data stored in the array is a bunch of zero’s.
There was no need to return a new array since the array b just pointed to the memory location of
the passed array values, so when you made modifications to array b, it changed the data in that
location which array a was already pointing to back in your main method.

Be careful with objects and arrays that are passed by reference, it could make your programming
easier but it may be the source of why your program is not working as expected.

IB Computer Science

1. Yearly Equivalent Interest Rate
Write a method that will convert a yearly percentage rate r compounded n times to its equivalent rate compounded once per year. Accept the yearly interest rate r and the number of compounds as arguments. Return the equivalent interest rate. Test the program by reading in 5 rates from a file. Use the formula below:

2. Even Numbers
Write a method that determines how many even numbers are in an array. Test the program with an array of 1000 random numbers between 50 and

3. Cosine Law
Write a method that accepts the 3 sides of a triangle and returns an angle. Test the program by asking the user for the 3 sides and then use the method to output all 3 sides.

4. Perfect Square
Write a method that determines if a number is a perfect square. Return true if it is and false if it is not. Test the program by using the method to find all the perfect squares less than 10000.

Looking to Learn More about Computer Science and Coding?

Check out our programing in python courses that focus on high school level coding.  

  • Grade 11 Computer Science ICS3U
  • Grade 12 Computer Science ICS4U

These courses are complete with interactive coding lessons, teacher led videos, and more practice questions with complete solutions

Return To International Baccalaureate Computer Science Main Page